Issue
When the model's ManyToMany field is updated and a m2m_changed signal is sent I am getting every item, previously related and new items, for that relationship in the pk_set argument. Is this the correct behavior? I was expecting only the new item or multiple items that were added to the relationship to be present in the pk_set.
If that is the expected behavior, is there a better way to get only the new items being added to the relationship other than using the post_add signal and comparing the list of items already associated with the model with the incoming list?
Edit: It appears there are no items related to the ManyToMany field in pre_add, then all of the items are there on post_add.
Edit 2: Ok, so the many to many relationship is getting cleared before the list of items is added, receiving the pre_clear and post_clear actions. Not sure how I am supposed to get a diff of how the set of items has changed.
Solution
It looks like a better spot to do this comparison is in the model's admin in save_model(). There I can get the original object and the form being applied.
Answered By - Caleb S
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.