Respond to review feedback

This commit is contained in:
Neil Martinsen-Burrell 2022-09-26 11:51:15 -05:00
parent 5c3460782e
commit 60f282752b
No known key found for this signature in database
GPG key ID: 6A3C818CC10D0184
12 changed files with 69 additions and 119 deletions

View file

@ -6,12 +6,19 @@ from .models import UserProfile
@receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs):
if created:
def handle_profile(sender, instance, **kwargs):
"""Method for when a User is saved.
If the user is being created, then create a matching UserProfile. Otherwise
save an updated profile or create one if it doesn't exist.
"""
if kwargs.get("created", False):
UserProfile.objects.create(user=instance)
@receiver(post_save, sender=User)
def save_profile(sender, instance, **kwargs):
# instance is a User, it has a profile from the one-to-one relation
instance.userprofile.save()
else:
# the user is not being created.
if hasattr(instance, "userprofile"):
instance.userprofile.save()
else:
UserProfile.objects.create(user=instance)