In the system I am building user CAN NOT register them selves. The users are added by one of the system admins. So there is no user registration form or view. The registration is only being done in the admin so I guess that the send_mail has to be over there also (or am I wrong)?
I need to send an automatic email to the user when he/she is being created and only then (not on every save of the model).
Can any one help with this? Is there a built-in something for that? or how do I do that?
I've read about the create_user user Manager, but I thought there is a better way then editing a manager.
score:6
You can register a callback on the post_save signal for the User model. Somewhere along the lines of:
# note: untested code
from django.db.models.signals import post_save
from django.contrib.auth.models import User
def email_new_user(sender, **kwargs):
if kwargs["created"]: # only for new users
new_user = kwargs.["instance"]
# send email to new_user.email ..
post_save.connect(email_new_user, sender=User)
Note the if kwargs["created"]:
condition which checks if this is a newly created User instance.
score:1
You can use the signals framework. A post-save signal on User objects will be appropriate, see here for a similar example.
score:2
Use the post_save signal, which has a created
argument sent with the signal. If created is true, send your email.
Edit
Shawn Chin beat me to it. Accept his answer
Credit To: stackoverflow.com
Related Query
- Is there a way to send a user email when user object is created?
- Is there a proper way of ensuring only one user at a time makes changes to an object with REST+HTTP?
- Is there a way for angular to get the current user when using basic login from django
- Send User detail to his email when django admin creates user
- Django : Send a mail to user when entry is created
- Django send email to the user when a specific field on a model has bean changed
- django-registration send email when user is set as active
- Is there a way to automate creation of pages(and slugs) as and when a record is created in Django
- is there a simple way to get group names of a user in django
- django - set user permissions when user is automatically created using get_or_create
- Django: Is there a way to keep the dev server from restarting when a local .py file is changed and dynamically loaded?
- How to auto insert the current user when creating an object in django admin?
- In django, is there a way to directly annotate a query with a related object in single query?
- "[Errno 101] Network is unreachable" when trying to send email using Django
- STARTTLS extension not supported by server - Getting this error when trying to send an email through Django and a private email address
- Is there an idiomatic way to get_or_create then update an object in Django?
- Is there any way to change username field label in user authentication login page?
- Is there a way to check whether a related object is already fetched?
- Django set creator/owner for the object when created
- Invalid Literal error when adding a user permission to a Django user object
- Is there a pythonic way of knowing when the first and last loop in a for is being passed through?
- Is there any way to use django shell without restarting when change code
- "Permission denied" when trying to send verification email
- Django: Best way to send email in background?
- Is there an event or another way to call a Javascript function when a Django Admin Popup (the green plus icon) completes?
- Is there any way to edit the request user in django middleware?
- django creating a row in userprofile table when a user is created
- In Django is there a way to aggregate over relationships with a condition on the related object
- Is there any way to get current user from the request? I am getting annonymous user even though user is loggedin
- Is there a way to resist unnecessary joins that are only checking id existence when using Django's orm?
More Query from same tag
- Cannot create an instance of a model with GenericForeignKey in migration
- Load all third party scripts using requests or mechanize in Python
- All of the disqus comments are showing up on all the blog pages
- Django Rest Framework: AttributeError when Serializer many=False, but not when many=True
- Validation error in Django 'POST' request
- set custom basePath in drf-yasg
- Django Bash completion not working on manage.py
- Django behind nginx: secure & robust way to get remote IP address
- How to write regex properly in re_path django 3
- Django application not visible
- DjangoCMS cant find templates - TemplateDoesNotExist at /admin/djangocms_blog/post/add/
- Dynamic queryset into form
- How to start Django up programmatically
- How do you join two tables on a foreign key field using django ORM?
- ImportError No module named localflavor.us.forms in Django 1.7