I have a Custom User Model and a separate Profile Model with django all-auth.
The following signal creates the profile for the user and then informs the admin that a new user has registered.
@receiver(post_save, sender=User)
def create_user_profile(sender, **kwargs):
'''Create a profile for a new user'''
if kwargs['created']:
Profile.objects.create(user=kwargs['instance'])
@receiver(post_save, sender=User)
def notify_admin(sender, instance, created, **kwargs):
'''Notify the administrator that a new user has been added.'''
if created:
subject = 'New Registration created'
message = 'A new candidate %s has registered with the site' % instance.email
send_mail(subject, message, from_addr, recipient_list)
This works fine and using Mailhog I get the email informing me of the new user.
Where I am stuck, is that I also want to inform the admin when a profile is updated. However, for the life of me I cannot fathom out how to do this!
Any help would be appreciated.