From a82da3a347725779d8be788a5953c8a4140e3b1d Mon Sep 17 00:00:00 2001 From: J Sikes <31295952+TechRancher@users.noreply.github.com> Date: Thu, 3 Sep 2020 19:49:56 -0500 Subject: [PATCH] Update models.py Add this to use to allow social_Auth users to edit and save profile --- Chapter04/bookmarks/account/models.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Chapter04/bookmarks/account/models.py b/Chapter04/bookmarks/account/models.py index bb3deb2..89df530 100644 --- a/Chapter04/bookmarks/account/models.py +++ b/Chapter04/bookmarks/account/models.py @@ -1,5 +1,6 @@ from django.db import models from django.conf import settings +from django.dispatch import receiver // Add this to use to allow social_Auth users to edit and save profile class Profile(models.Model): @@ -9,3 +10,12 @@ class Profile(models.Model): def __str__(self): return f'Profile for user {self.user.username}' + + // This will allow social_Auth users to edit and save profiles. + @receiver(post_save, sender=User) + def create_user_profile(sender, instance, created, **kwargs): + if created: + Profile.objects.create(user=instance) + @receiver(post_save, sender=User) + def save_user_profile(sender, instance, **kwargs): + instance.profile.save()