admin管理员组文章数量:1123425
I create my custom user and group as below:
models.py (myusers app)
` from django.db import models from django.contrib.auth.models import AbstractUser, GroupManager, Permission
class AbstractGroup(models.Model):
name = models.CharField(_("name"), max_length=150, unique=True)
permissions = models.ManyToManyField(
Permission,
verbose_name=_("permissions"),
blank=True,
related_name="fk_group_permission",
)
objects = GroupManager()
def __str__(self):
return self.name
def natural_key(self):
return (self.name,)
class Meta:
verbose_name = _("group")
verbose_name_plural = _("groups")
abstract = True
class Group(AbstractGroup):
is_active = models.BooleanField(_("Is Active"), default=True)
class User(AbstractUser):
groups = models.ManyToManyField(
Group,
verbose_name=_("groups"),
blank=True,
help_text=_(
"The groups this user belongs to. A user will get all permissions "
"granted to each of their groups."
),
related_name="user_set",
related_query_name="user",
)
`
and point in settings.py:
AUTH_USER_MODEL=myusers.User AUTH_GROUP_MODEL=myusers.Group
All is ok but when get group permissions (a_user.get_all_permissions() or a_user.get_group_permissions()) raise error: ValueError: Cannot query “a_user”: Must be “Group” instance. (a_user here is the user user instance) what is wrong?
The get_group_permissions() return error.
本文标签: Can not get group permissions by django custom User and GroupStack Overflow
版权声明:本文标题:Can not get group permissions by django custom User and Group - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736570734a1944769.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论