Complete the code to import the Django signal dispatcher.
from django.dispatch import [1]
The receiver decorator is imported from django.dispatch to connect signal handlers.
Complete the code to connect a signal handler to the post_save signal of a model.
@receiver([1], sender=MyModel) def my_handler(sender, instance, **kwargs): pass
pre_save which triggers before saving.The post_save signal is sent after a model instance is saved, so the handler should listen to it.
Fix the error in the signal handler connection by completing the missing import.
from django.db.models.signals import [1] @receiver(post_save, sender=User) def user_saved(sender, instance, **kwargs): print('User saved!')
The post_save signal must be imported from django.db.models.signals to be used in the handler.
Fill both blanks to connect a handler to the pre_delete signal for the Article model.
from django.db.models.signals import [1] @receiver([2], sender=Article) def before_delete(sender, instance, **kwargs): print('Article will be deleted')
Both the import and the decorator must use the pre_delete signal to connect the handler properly.
Fill all three blanks to create a signal handler that listens to post_save for Profile and prints the instance's username.
from django.db.models.signals import [1] from django.dispatch import [2] @[2]([1], sender=Profile) def profile_saved(sender, instance, **kwargs): print(f"Saved profile for {instance.username}")
The post_save signal is imported and used with the receiver decorator to connect the handler.