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. Callable object as signal receiver by diverman 2 years, 10 months ago
  2. Profanity Check by menendez 2 years, 6 months ago
  3. Who's helping a lot in IRC by akaihola 3 years, 9 months ago
  4. Generic Recievers For Signals by ericmoritz 3 years, 8 months ago
  5. "Autoconnect" model decorator, easy pre_save and post_save signal connection by bendavis78 1 year, 6 months ago

Comments

(Forgotten your password?)