diff --git a/tom_common/signals.py b/tom_common/signals.py index 374761f6..e2e76191 100644 --- a/tom_common/signals.py +++ b/tom_common/signals.py @@ -1,4 +1,4 @@ -from django.db.models.signals import post_save, pre_delete +from django.db.models.signals import post_save from django.contrib.auth.models import User from django.dispatch import receiver from tom_common.models import Profile @@ -14,4 +14,9 @@ def create_profile(sender, instance, created, **kwargs): @receiver(post_save, sender=User) def save_profile(sender, instance, **kwargs): """When a user is saved, save their profile.""" - instance.profile.save() + # Take advantage of the fact that logging in updates a user's last_login field + # to create a profile for users that don't have one. + try: + instance.profile.save() + except User.profile.RelatedObjectDoesNotExist: + Profile.objects.create(user=instance)