traviscline (owner)

Forks

Revisions

gist: 88958 Download_button fork
public
Public Clone URL: git://gist.github.com/88958.git
Embed All Files: show embed
Python #
1
2
3
4
5
6
7
8
9
10
11
def comment_saved_handler(sender, instance, created, **kwargs):
    """
Signal handler to populated comment count fields.
Bound to 'comment_count' field, should probably be checking for a field annotation in the model.
"""
    if 'comment_count' in [f.name for f in instance.content_object._meta.fields]:
        instance.content_object.count = instance.content_object.comments.count()
        instance.content_object.save()
 
from django.contrib.comments.models import Comment
post_save.connect(comment_saved_handler, sender=Comment)