[Answer]-Assigning values to extended User model in Django

1👍

Using a separate model with a OneToOne is no longer recommended, since you can extend the User model directly instead. That said, what’s wrong here is that your signal is creating the Appuser, but then you try and create another one. Instead, get the one that was created by the signal:

user = User.objects.create_user('John Doe')
appuser = Appuser.objects.get(user=user)
appuser.accesstoken = '634646473'
appuser.socialid = 6436
appuser.save()

Note that normally you can get from user to appuser by just doing user.appuser, but this probably won’t work at this point because the appuser didn’t exist at the time you got the User. The next time you get either the Appuser or the User from the db, the direct reference will work.

Leave a comment