Add User and UserProfile models

This commit is contained in:
Neil Martinsen-Burrell 2022-09-22 12:13:53 -05:00
parent 331d2e575a
commit e0b3023520
No known key found for this signature in database
GPG key ID: 6A3C818CC10D0184
11 changed files with 391 additions and 0 deletions

17
src/registrar/signals.py Normal file
View file

@ -0,0 +1,17 @@
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from django.dispatch import receiver
from .models import UserProfile
@receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs):
if created:
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()