Django:如何在Custom UserAdmin中显示Groups字段?

时间:2017-03-10 01:46:39

标签: python django django-forms django-admin

我创建了一个自定义User类和一个自定义UserAdmin / Form类。一切都很好,但我仍然缺少groups字段(auth_group)。 我不知道字段名称。

https://gist.github.com/CoinBR/c49c05f24bd5dcd3b4d4f2d205143a2e

Django版本:1.10

1 个答案:

答案 0 :(得分:2)

您可以在PermissionsMixin课程内看到:

"""
A mixin class that adds the fields and methods necessary to support
Django's Group and Permission model using the ModelBackend.
"""
...
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",
)
...

所以它的名字是groups。您必须在UserCreateForm字段和UserAdmin字段集中添加它。