Django - Signals
Consider this Django code snippet:
What will be printed when the above code runs?
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
class Book(models.Model):
title = models.CharField(max_length=100)
@receiver(post_save, sender=Book)
def notify_save(sender, instance, created, **kwargs):
if created:
print(f"New book created: {instance.title}")
else:
print(f"Book updated: {instance.title}")
book = Book(title='Django Unchained')
book.save()What will be printed when the above code runs?
