-
-
Save nathanborror/88959 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment