1 2 3 4 5 6 7 8 9 | # Register some signal handlers
def denormalize_votes(sender, instance, created=False, **kwargs):
"""This recalculates the vote total for the object
being voted on"""
instance.object.vote_score = Vote.objects.get_score(instance.object)['score']
instance.object.save()
models.signals.post_save.connect(denormalize_votes, sender=Vote)
models.signals.post_delete.connect(denormalize_votes, sender=Vote)
|
More like this
- Callable object as signal receiver by diverman 2 years, 10 months ago
- Profanity Check by menendez 2 years, 6 months ago
- Who's helping a lot in IRC by akaihola 3 years, 9 months ago
- Generic Recievers For Signals by ericmoritz 3 years, 8 months ago
- "Autoconnect" model decorator, easy pre_save and post_save signal connection by bendavis78 1 year, 6 months ago
Comments