Friday, January 30, 2015

Changing many-to-many using Admin Site never calls post_remove Signal

I have a many-to-many relationship which the Admin can change using the Admin Site. I use a ModelAdmin.filter_horizontal, but even with the default widget it's the same.

I registered a receiver when m2m_changed, however it always only calls: pre_clear, post_clear, pre_add, post_add, in that order.

Now for post_add I have code to execute, to create new objects in the database, however when a value is removed from this many-to-many field, I need to delete some objects. Since pre_remove is never called, I can't tell which value was removed and I'm unable to find out which objects to delete.

Is there a way to modify the Admin page to actually call remove / add on the Model? Or I need another way to find out which value was removed.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2b9b7689-ded9-4e7a-88c5-5775e70268f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment