On Wed, Feb 15, 2012 at 12:37 AM, Marc Aymerich <glicer...@gmail.com> wrote:
> On Tue, Feb 14, 2012 at 8:02 PM, Jeff Blaine <cjbla...@gmail.com> wrote:
>> Hi all,
>>
>> I'm having trouble detecting changes that happen to a M2M field behind the
>> scenes: as a result of one of the *referenced objects being deleted*
>>
>> I'm using Django 1.3.1 with PostgreSQL 8
>>
>> Let's say we have the following simple proof of concept models:
>>
>> class Topping(models.Model):
>>     name = models.CharField()
>>
>> class Pizza(models.Model):
>>     name = models.CharField()
>>     toppings = models.ManyToManyField(Topping, null=true, blank=true)
>>
>> And this data established using those models:
>>
>>     TOPPING
>>     id=1, name="Pepperoni"> Register a post_delete signal for Topping?  How 
>> do I refer to or find the
>>     id=2, name="Onion"
>>     id=3, name="Mushroom"
>>
>>     PIZZA
>>     id=1, name="foopizza"
>>     toppings=1,2,3
>>
>> Known Facts:
>>
>> 1. Deleting any Topping object (for example, deleting id=1,
>> name="Pepperoni") also removes it from foopizza.toppings.  Good.
>> 2. No m2m_changed signal is sent when 1 (above happens).  BAD.
>>
>> How do I tie into "topping *object* was deleted (no longer for sale),
>> perform custom code on ALL Pizza objects that referenced it" ?
>>
>> Register a post_delete signal for Topping?  How do I refer to or find the
>> Pizza objects that referred to it?
>>
>
> You can introspect topping model looking for pizza m2m relation-like:
> take a look at Topping._meta attribute, and then send a custom signal
> for each related objects when a topping is deleted.

Check this out ;)
https://docs.djangoproject.com/en/dev/ref/signals/#m2m-changed

-- 
Marc

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to