#NEWLINE# def count_discussions_handler( sender , **kwargs ) : #NEWLINE# #INDENT# '\n    Update the count of each type of discussion on an entry.\n    ' #NEWLINE# if ( kwargs . get ( 'instance' ) and kwargs . get ( 'created' ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# comment = ( ( ( 'comment' in kwargs ) and kwargs [ 'comment' ] ) or kwargs [ 'instance' ] ) #NEWLINE# entry = comment . content_object #NEWLINE# if isinstance ( comment , Entry ) : #NEWLINE# #INDENT# entry . comment_count = entry . comments . count ( ) #NEWLINE# entry . pingback_count = entry . pingbacks . count ( ) #NEWLINE# entry . trackback_count = entry . trackbacks . count ( ) #NEWLINE# entry . save ( update_fields = [ 'comment_count' , 'pingback_count' , 'trackback_count' ] )