Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does Django post_save signal give me pre_save data?
    primarykey
    data
    text
    <p>Im trying to connect a "Information" object to many "Customers" (see code below)</p> <p>When one Information object is updated, I want to send email to each Customer that is connected to the Information.</p> <p>However, when I log the sold_to field that the signal recieves I always get what the data is like BEFORE the save.</p> <p>I'm guessing this is because its ManyToManyField and the data is stored in a separate table, but shouldn't the post_save signal be called after all relations have been updated?</p> <p>Anyone got a suggestion for a solution?</p> <pre><code>class Customer name = models.CharField(max_length=200) category = models.ManyToManyField('Category',symmetrical=False) contact = models.EmailField() class Information name = models.CharField(max_length=200) email = models.EmailField(max_length=200) mod_date = models.DateTimeField(auto_now=True) sold_to = models.ManyToManyField(Customer, null=True, blank=True) def send_admin_email(sender, instance, signal, *args, **kwargs): from myapp import settings for cust in instance.sold_to.all(): settings.debug(cust.name) post_save.connect(send_admin_email, sender=Information) </code></pre> <p>Edit: apollo13 in #django alerted me to this: "Related items (the things being saved into the many-to-many relation) are not saved as part of a model's save method, as you have discovered." - <a href="http://groups.google.com/group/django-users/msg/2b734c153537f970" rel="noreferrer">http://groups.google.com/group/django-users/msg/2b734c153537f970</a></p> <p>But since its from Jul 9 2006 I really really hope there is a solution for this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload