@register.filter(name='rule_member_count')
def rule_member_count(instance, member):
 member = getattr(instance, member)
 counts = member.all().count()
 return str(counts)

@ register . filter ( name = 'rule_member_count' ) def rule_member_count ( instance , member ) : member = getattr ( instance , member ) counts = member . all ( ) . count ( ) return str ( counts )
instance is a rule object .