Search code examples
djangoresttastypie

Hydrate not called


I am trying to hash a value received from the client side, to compare it with the hashed value matching a username.

Here is the call:

http://localhost:8000/api/user/?format=json&name__exact=jean&nickname__exact=mynickname

Here is my resource:

class MUserResource(ModelResource):
    class Meta:
        queryset = MUser.objects.all()
        resource_name = 'user'
        filtering = {
            'name': ['exact'],
            'nickname': ['exact'],
        }

    def dehydrate_nickname(self, bundle):
        bundle.data['nickname'] = hashlib.sha1(bundle.data['nickname']).hexdigest()
        return bundle.data['nickname']

Any hints?


Solution

  • You want to use dehydrate_foo and not hydrate_foo. Hydrate is used for when you de-serialize your incoming data.