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
- Manager introspecting attached model by ubernostrum 5 years, 2 months ago
- Binding signals to abstract models by andreterra 1 year ago
- Generic Recievers For Signals by ericmoritz 4 years, 11 months ago
- Automatic slug generation signal by danux 1 year, 10 months ago
- Profanity Check by menendez 3 years, 10 months ago
Comments