Sending email when user is activated in Django admin

I am going to create a website that controlled registration, in which only certain people are allowed to register. Undoubtedly, some discrepancies will be recorded, despite the fact that I write above the registration form, so we are going with moderation.

After registration, a django.contrib.auth Userprofile will be created and an email will be sent to the moderator. The moderator will log in to the Django admin site, check that this is someone who is allowed to register and mark their account active. If they mistakenly try to slip, the account will be deleted.

I will use recaptcha to try to stop automatic attempts.

I would like to disable email when the account is activated or deleted so that the account holder knows what happened to their account and that they can log in or tell them that we know that they and they should stop being stupid .

I suspect this has something to do with the signals, but frankly, I have no idea where this really fits, given that I am using the prefab model provided django.contrib.auth.

Any hints, tips or code are welcome.

+3
source share
2 answers
from django.db.models.signals import post_save
from django.contrib.auth.models import User

def send_user_email(sender, instance=None, **kwargs):
    if kwargs['created']:
        #your code here
post_save.connect(send_user_email, sender=User)

Something like this should work. Here are the documents.

+1
source

Signals.

+1

Source: https://habr.com/ru/post/1758762/


All Articles