I wrote some smart generic counters and managers for my models (to avoid select count
queries etc.). Therefore I got some heavy logic going on for post_save.
I would like to prevent handling the signal when there's no need to. I guess the perfect interface would be:
instance.save(dispatch_signal=False)
How can I accomplish this?
Update
More information about what I'm doing, if anyone's interested:
- Generic counters are stored in a separate table
- Every time Django paginates an object list, it calls overriden count() method of my custom manager, which basically retrieves the static counter value for appropriate object class.
- Signals trigger the logic of counters update, which is a bit complicated since it checks many aspects of related models (i.e. it has to generate a visibility property based on a nested category tree). I can't put this logic in Model.save() because one counter depends on many different models. I'd like to have that logic in one piece, instead of fragments spread around.
- I am denormalizing some of my models, so I rewrite (duplicate) certain values across tables.
- For testing purposes I run my little command-extension -- Dilla, to populate random data around.
- I've noticed unwanted signals triggering, therefore I'd like them to run conditionally.
Hope it's clear enough. Excuse my language mistakes.