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

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

    if (getattr(obj, 'pk', None) is None):
        raise Exception(('Object    %s    needs    to    be    persisted    first' % obj))
    ctype = ContentType.objects.get_for_model(obj)
    permission = Permission.objects.get(content_type=ctype, codename=perm)
    kwargs = {'permission': permission, 'user': user}
    kwargs['content_type'] = ctype
    kwargs['object_pk'] = obj.pk
    (obj_perm, created) = self.get_or_create(**kwargs)
    return obj_perm
