Signals and Profile Update

57 views
Skip to first unread message

dtdave

unread,
Sep 17, 2018, 12:07:52 PM9/17/18
to Django users
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
        from_addr = 'no-r...@example.com'
        recipient_list = ('ad...@example.com',)
        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.

carlos

unread,
Sep 17, 2018, 1:02:56 PM9/17/18
to django...@googlegroups.com
hello
the only thing you can do is compare dates of storage of the information and then check if the current date is greater than the saved date is an update

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fd387ab3-5993-4c54-b60b-7b16cf122c52%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
att.
Carlos Rocha
Reply all
Reply to author
Forward
0 new messages