简体   繁体   English

将用户和组保留在Django管理面板中的相同部分

[英]Keep User and Group in same section in Django admin panel

I have made my own User model in Django 1.8 with 我在Django 1.8中制作了自己的User模型

from django.contrib.auth.models import AbstractUser, Group, Permission

class MyUser(AbstractUser):
    pass

But it does not figure in admin any longer. 但它不再在管理员中出现。

I have tried adding it to the admin page with 我尝试将其添加到管理页面

from django.contrib.auth import get_user_model, models as auth_models
from django.contrib.auth.admin import UserAdmin

UserModel = get_user_model()

class MyUserAdmin(UserAdmin):
    pass

admin.site.register(UserModel, MyUserAdmin)

and it does figure in admin now but in a different 'section' than Group . 并且它在管理人物,但现在比一个不同的“部分” Group How can I keep User in the default section in the admin panel? 如何将User保留在管理面板的默认部分?

You need to add app_label to Meta class of MyUser. 您需要将app_label添加到app_label的Meta类。

class MyUser(AbstractUser):
    pass
    class Meta:
        app_label = 'auth'

Official documentation on app_label . 有关app_label的官方文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM