My issue is similar to a few other questions asking about handling M2M fields when saving an object, eg.
Django accessing ManyToMany fields from post_save signal
Django: Using signals to save a ManyToMany field
Basically, in order to work with M2M fields you need to listen for m2m_changed
rather than post_save
.
The problem I have is that I want my operations to occur only when creating a new object -- post_save
gets a created
argument, but as far as I can tell there's nothing similar for m2m_changed
, and by the time the m2m_changed
signal is triggered the object has been saved and given a PK, so there's no way to tell from the signal handler whether it's a newly created object or an existing object that was updated.
Is there any way around this?