def set_object_perm(self, instance, perm):
    perms = instance.perms.as_int(perm)
    if isinstance(self, User):
        try:
            the_permission = instance.user_perms_set.get(user=self)
        except UserPermission.DoesNotExist:
            the_permission = instance.user_perms_set.create(user=self)
    elif isinstance(self, Group):
        try:
            the_permission = instance.group_perms_set.get(group=self)
        except GroupPermission.DoesNotExist:
            the_permission = instance.group_perms_set.create(group=self)
    else:
        raise Exception("This method should only be attached to a User or Group object.")
    the_permission.permission = perms
    the_permission.save()
Sets the permission to the ``perm`` value. Same as revoking all privileges
dataset/ETHPy150Open callowayproject/django-objectpermissions/objectpermissions/registration.py/set_object_perm