def get_groups_with_perms(obj, attach_perms=False):
 ctype = get_content_type(obj)
 if (not attach_perms):
  group_model = get_group_obj_perms_model(obj)
  group_rel_name = group_model.group.field.related_query_name()
  if group_model.objects.is_generic():
   group_filters = {(u'%s__content_type' % group_rel_name): ctype, (u'%s__object_pk' % group_rel_name): obj.pk}
  else:
   group_filters = {(u'%s__content_object' % group_rel_name): obj}
  groups = Group.objects.filter(**group_filters).distinct()
  return groups
 else:
  groups = {}
  for group in get_groups_with_perms(obj):
   if (group not in groups):
    groups[group] = sorted(get_group_perms(group, obj))
  return groups

def get_groups_with_perms ( obj , attach_perms = False ) : ctype = get_content_type ( obj ) if ( not attach_perms ) : group_model = get_group_obj_perms_model ( obj ) group_rel_name = group_model . group . field . related_query_name ( ) if group_model . objects . is_generic ( ) : group_filters = { ( u'%s__content_type' % group_rel_name ) : ctype , ( u'%s__object_pk' % group_rel_name ) : obj . pk } else : group_filters = { ( u'%s__content_object' % group_rel_name ) : obj } groups = Group . objects . filter ( ** group_filters ) . distinct ( ) return groups else : groups = { } for group in get_groups_with_perms ( obj ) : if ( group not in groups ) : groups [ group ] = sorted ( get_group_perms ( group , obj ) ) return groups
returns queryset of all group objects with *any* object permissions for the given obj .