@register.filter
def subgroup_state(sg, dv):
    x = dv.subgroupstatefordelivery_set.filter(delivery=dv, subgroup=sg)
    return (x[0].state if x else m.SubgroupStateForDelivery.DEFAULT)
@register.filter
def subgroup_state(sg, dv):
    x = dv.subgroupstatefordelivery_set.filter(delivery=dv, subgroup=sg)
    return (x[0].state if x else m.SubgroupStateForDelivery.DEFAULT)