2

I'm looking to use an Account model I created to handle financial data about a user. How do I ensure django-allauth will create this model when registering users and will link through keys both the new user and the Account model?

Alex Creamer
  • 29
  • 1
  • 4

1 Answers1

1

You can implement custom pipeline. First modify SOCIAL_AUTH_PIPELINE in django settings file like this:

SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.user.get_username',
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
'yourapp.pipeline.add_account'
)

Then in yourapp create pipeline module or you can use already existing model and inside this model create function add_account with following code:

def add_account(backend, details, response, user=None, is_new=False, *args, **kwargs):
    if is_new:
        Account.objects.create(user=user)

You can find more details here and here.

UPDATE

Pipelines is just functions wich will be called by django-allauth during autentication process. So you can add some custom function to this procedure.

neverwalkaloner
  • 46,181
  • 7
  • 92
  • 100