I'm trying to understand the signals and use it in my application. However, even though including this signal does not give me any error message, and from Django admin panel, I can actually add a movie successfully, I can NOT see the message 'movie created' printed in my terminal when this happens. Anyone could see why? Thank you so much for any help!
models.py ...
from django.db.models.signals import post_save
class Movie(models.Model):
name = models.CharField(max_length=30)
description = models.TextField(blank=True)
rating = models.IntegerField(default=0, blank=True, null=True)
class MovieGenre(models.TextChoices):
Action = 'Action'
Horror = 'Horror'
History = 'History'
New = 'New'
genre = MultiSelectField(
choices=MovieGenre.choices,
max_choices=3,
min_choices=1
)
def average_rating(self):
rating = self.movierate_set.aggregate(Avg('rating'))['rating__avg']
return rating
class Meta:
ordering = ["-upload_date"]
def __str__(self):
return self.name
def create_movie(sender, instance, created, **kwargs):
if created:
Movie.objects.create(name=instance)
print('movie created')
post_save.connect(create_movie, sender=Movie)