Simple Signal to denormalize vote counts in django-voting

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

  1. Manager introspecting attached model by ubernostrum 5 years, 2 months ago
  2. Binding signals to abstract models by andreterra 1 year ago
  3. Generic Recievers For Signals by ericmoritz 4 years, 11 months ago
  4. Automatic slug generation signal by danux 1 year, 10 months ago
  5. Profanity Check by menendez 3 years, 10 months ago

Comments

(Forgotten your password?)