mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-14 06:55:08 +02:00
Respond to review feedback
This commit is contained in:
parent
5c3460782e
commit
60f282752b
12 changed files with 69 additions and 119 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue