Skip to content

Instantly share code, notes, and snippets.

@mansha99
Last active July 9, 2023 09:19
Show Gist options
  • Save mansha99/5ea8ef171cd0cdb420db5b29da0fa397 to your computer and use it in GitHub Desktop.
Save mansha99/5ea8ef171cd0cdb420db5b29da0fa397 to your computer and use it in GitHub Desktop.
project_app_receivers.py
from django.dispatch import receiver
from helloapp import signals
from .models import Notice
from django.db.models import signals as modelSignals
#Predefined Model signal
@receiver(modelSignals.post_save, sender=Notice)
def valid_notice_created(sender, instance, created, **kwargs):
if created:
message = "Notice Created : id = {id} ".format(id=instance.id)
print(message)
#custom signal
@receiver(signals.invalid_notice_signal)
def invalid_notice_created(sender, **kwargs):
message = "Alert!!! Someone tried to create Invalid notice"
print(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment