DEV Community

sium_hossain
sium_hossain

Posted on • Edited on

Django signal...

There are seven built-in signals in Django -
pre_save: Signal sent before model save() method is called.
post_save: Signal sent after model save() method is called.
pre_delete: Signal sent before model delete() method is called.
post_delete: Signal sent after model delete() method is called.
m2m_changed: Signal sent when a ManyToMany field is changed
request_started: Signal sent when HTTP request start.
request_finished: Signal sent when HTTP request finished.

from django.dispatch import receiver
from django.db.models.signals import pre_save
@receiver(pre_save, sender=User)
def pre_save_user(sender, instance, created, **kwargs): 
    if created:
              #your logic 

Enter fullscreen mode Exit fullscreen mode

Top comments (0)