0

I have models like

class Genre(models.Model):
      name = models.CharField(max_length=50)

class Cast(models.Model):
      name = models.CharField(max_length=120, null=False, blank=False)

class movie:
      name = models.CharField(max_length=120, null=False, blank=False)
      genre = models.ManyToManyField(Genre)
      cast = models.ManyToManyField(Cast, null=True, blank=True)

I want to send notification to clients after a movie saved so i used post_save signal and because of my m2m relationships it didn't work and after that i used m2m_changed and now everytime i make a change on movie genres or movie cast they will be notified! i want them to be notified just for the first time the movie submits and i need the genres too!

I mean the problem with the post_save signal was, it happens before genre and cast objects submit so i didn't have access to them.

Ebrahim Karimi
  • 732
  • 8
  • 24
  • Look this thread https://stackoverflow.com/questions/17368707/django-how-to-execute-code-only-after-the-first-time-a-m2m-relationship-is-adde – Maykel Llanes Garcia Dec 29 '17 at 17:53
  • Check this : https://stackoverflow.com/questions/41533443/addhow-to-make-django-post-save-signal-run-only-during-creation, Solved here https://stackoverflow.com/questions/41533443/addhow-to-make-django-post-save-signal-run-only-during-creation – Maykel Llanes Garcia Dec 29 '17 at 17:59
  • @Mayk thanks for comment but it didn't solve it by post_save, because it doesn't give me m2m relations and as i said, i need them – Ebrahim Karimi Dec 29 '17 at 18:02
  • Look: "Django's m2m_changed signal offers you an action argument. You could check in your signal receiver if the action is pre_add and then check if already a reminder exists. This will work except for the case when all reminders get deleted and a new one gets created - don't know if it's ok for you to execute the code then. Otherwise the only possibility is storing additional data, eg. you could set a boolean to True at the first time or store the instance as well in your Message object, so you can check if a message already exists..." – Maykel Llanes Garcia Dec 29 '17 at 18:25

1 Answers1

0

I had to add a BooleanField to movie model named notified, and after first time i check and and everytime before sending i check if it have been checked and thanks to @Mayk, he was part of the idea

Ebrahim Karimi
  • 732
  • 8
  • 24