How to properly override User admin in Django(如何在 Django 中正确覆盖用户管理员)
问题描述
我想在 Django 管理中添加添加内联模型并从用户更改表单中排除一些字段.
I want to add add inline model and exclude some fields from User change form in Django admin.
我正在尝试覆盖 Django 的内置 UserAdmin 以保留用户更改设计:
I'm trying to override Django's built-in UserAdmin to preserve User change design:
class UserCustomAdmin(UserAdmin):
# list_display = ['id', 'username','email', 'last_login']
exclude = ['groups','user_permissions']
inlines = [UserProfileInline]
即使 exclude = ['groups'] 也会引发错误:
Even exclude = ['groups'] raises error:
u"在 'UserForm' 中找不到键 'groups'.选项有:date_joined,电子邮件、名字、is_active、is_staff、is_superuser、last_login、姓氏、密码、用户名."
u"Key 'groups' not found in 'UserForm'. Choices are: date_joined, email, first_name, is_active, is_staff, is_superuser, last_login, last_name, password, username."
如何让它发挥作用?
推荐答案
groups 字段出现在 UserAdmin.fieldsets 也是.我认为出现错误是因为您从表单中排除了该字段,但后来在字段集中定义并且表单失败.
groups field appears in the UserAdmin.fieldsets also.
The error appears, I think, because you exclude the field from form, but later is defined in the fieldsets and form fails.
尝试在没有 groups 字段的 UserCustomAdmin 中相应地覆盖 fieldsets.
Try to overwrite the fieldsets accordingly, in your UserCustomAdmin with no groups field.
这篇关于如何在 Django 中正确覆盖用户管理员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Django 中正确覆盖用户管理员
基础教程推荐
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
