0

I'm building a DRF app with Django-rest-auth implemented for social login. The problem I'm having now is that I want to extend my User Model, but I'm afraid if I change the User Auth Model migrations will complete destroy my project due to the rest-auth link.

So my option is to create a UserData field and hook it to User through a one to one field. However, I'm not sure how to instantiate a new UserData object and link it to the User every time a new user is sign up or created through Django-rest-auth api.

Any help and advice for this would be appreciated.

1

1 Answer 1

1

It looks like that django signal is your best way to achieve this.

You can simply register a receiver function which will be called everytime new user is created ( or model is updated ).

There you can create your UserData.

Example:

from django.db.models.signals import post_save
from django.dispatch import receiver

@receiver(post_save, sender=User)
def create_user_data(sender, update_fields, created, instance, **kwargs):
    if created:
        # Create your user data
        pass

created will be True if new instance has just been created. instance is the new user instance.

The sender is the model of your User ( not sure which one it is in case of django-rest-auth) - just make sure it is the correct one.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.