views:

29

answers:

2

I am working on a django project and i want to send a signal when something get's added to some models related set, e.g. we have an owner wo has a set of collectables and each time the method owner.collectable_set.add(something) is getting called i want signal like "collectable_added" or something. signals are clear to me, but in which manager(?) the "add" method sits that i want to override is unclear to me.

edit: Upon the request of Xaver to provide more details. You can easily override a models "save" method, by simply defining it and calling the super-"save" so it get's properly saved with some extra functionality for example. But i wonder where to override a related sets "add" method.

gosh, i think i haven't brought in any further details. but i think it even should be clear what i want to do from the first paragraph.

edit2: This is the method i want to override. Is it recommended to do so or do you suggest another way to place the sending of the signal?

A: 

I think you're looking for the RelatedManager Class.

Ofri Raviv
Thanks for you reply. It looks like the solution, but i forgot to mention that i am dealing with a m2m-relation. So in this case the ManyRelatedManager class would be the one to extend or to insert the signal into. BUT it is not trivial to extend this class since it is dynamically generated. Thanks anyway. I'll post a solution i found but haven't tested.
MB_
A: 

This is the solution i found, the m2m_changed signal. Took me quite some searchign and reading. Furthermore i found out that it is not trivial to extend the ManyRelatedManager class, which would have been the other option. But with the m2m_changed signal i can rely on build-in functions which is the preferred way most of the times.

MB_