django-social-auth with custom user model and overridden save() method

696 Views Asked by At

I'm using django-social-auth, and I'm really impressed by its simplicity, however I use a custom user model and I overrided the save() method in order to set a default computed value for a field I need, the problem is that save() is not called by socialauth! How can this be possible? Is there another way of setting a computed field value at creation-time?

1

There are 1 best solutions below

0
On

In order to solve the problem I created a custom "pipeline" (com.mysite.apps.users.social_auth.pipeline.addFacebookDetails) in which I add the necessary data to the user model only during its creation:

in settings.py:

SOCIAL_AUTH_PIPELINE = (
    'social_auth.backends.pipeline.social.social_auth_user',
    'social_auth.backends.pipeline.user.get_username',
    'social_auth.backends.pipeline.user.create_user',
    'com.mysite.apps.users.social_auth.pipeline.addFacebookDetails',
    'social_auth.backends.pipeline.social.associate_user',
    'social_auth.backends.pipeline.user.update_user_details',
)

in com.mysite.apps.users.social_auth.pipeline.addFacebookDetails.py:

def addFacebookDetails(*args, **kwargs):
    if kwargs['is_new']:
        user = kwargs['user']
        user.field1 = 'foo'
        user.field2 = 'bar'
    return None