#8077: Add ability to disable signals one a per-object-per-event basis.
----------------------------------------------+-----------------------------
Reporter: [email protected] | Owner: nobody
Status: new | Milestone:
Component: Core framework | Version: SVN
Resolution: | Keywords: signals
Stage: Design decision needed | Has_patch: 1
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
----------------------------------------------+-----------------------------
Comment (by EmilStenstrom):
lukeplant: Here's a realworld example:
I have a two models, dialog and comments, where the comment have a
foreignkey to the dialog. To speed up the display of number of comments I
have a denormalized field on dialog, called num_comments. Now, this needs
to be updated whenever a comment is added or deleted, so I listen to
post_save and post_delete:
{{{
# sender=Comment
def recalc_comments(sender, instance, created=False, **kwargs):
dialog = instance.dialog
dialog.num_comments = sender.public.filter(dialog=dialog).count()
dialog.save()
}}}
But this means that save will be run twice, since save() inside the signal
triggers the signal too. Adding disable_signals to the save inside the
signal would solve the problem I think.
Please let me know if this is not the right way to do this kind of thing.
Thanks.
--
Ticket URL: <http://code.djangoproject.com/ticket/8077#comment:12>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.