What are Django signals?

from django.db.models.signals 
pre_save & post_save#used before and after a model's save() method are used. By looking at the syntax, you can easily figure out the sender and receiver parts.pre_delete & post_delete#used before and after a model's delete() method or a query's delete() method are used.m2m_changed#used when a model's ManyToManyField has been changedrequest_started & request_finished#used when Django starts and finishes an HTTP request
from django.db.models.signals import pre_save
from django.contrib.auth.models import User #This code is in its own file, therefore I must import the user model.
def updateUser(sender, instance, **kwargs):
user = instance
if user.email != '':
user.username = user.email
pre_save.connect(updateUser, sender=User)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store