'Assigns permission with given ``perm`` for an instance ``obj`` and
``user``.'

def assign_perm(self, perm, user_or_group, obj):

    if (getattr(obj, u'pk', None) is None):
        raise ObjectNotPersisted((u'Object    %s    needs    to    be    persisted    first' % obj))
    ctype = get_content_type(obj)
    if (not isinstance(perm, Permission)):
        permission = Permission.objects.get(content_type=ctype, codename=perm)
    else:
        permission = perm
    kwargs = {u'permission': permission, self.user_or_group_field: user_or_group}
    if self.is_generic():
        kwargs[u'content_type'] = ctype
        kwargs[u'object_pk'] = obj.pk
    else:
        kwargs[u'content_object'] = obj
    (obj_perm, _) = self.get_or_create(**kwargs)
    return obj_perm
