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 中正确覆盖用户管理员


基础教程推荐
- 求两个直方图的卷积 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 包装空间模型 2022-01-01