imns
imns

Reputation: 5082

Django Tastypie, do stuff after creating a user

I'd like to add some values to my user Profile model after I create (POST) a user with Tastypie.

This is just one scenario, I have other instances where I might want to alter the data PRE or POST save in my tastypie resource. Is this possible or how would I go about achieving this?

Thanks for your help.

Upvotes: 0

Views: 708

Answers (2)

elynch
elynch

Reputation: 2240

You can also override obj_create on your Tastypie user resource. This will give you access to the bundle where the user object is and you can put more values to the fields there. Here's an example:

def obj_create(self, bundle, request=None, **kwargs):
    try:
        username = bundle.data['username']
        password = bundle.data['password']
        bundle.obj = User.objects.create_user(username,password)
        # add more stuff here

        bundle.obj.save()
        return bundle

Upvotes: 2

scytale
scytale

Reputation: 12641

Will a signal do what you want?

Upvotes: 2

Related Questions