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 中正确覆盖用户管理员
- 如何在 Python 的元组列表中对每个元组中的第一个值求和? 2022-01-01
- python-m http.server 443--使用SSL? 2022-01-01
- 如何将一个类的函数分成多个文件? 2022-01-01
- padding='same' 转换为 PyTorch padding=# 2022-01-01
- 沿轴计算直方图 2022-01-01
- 分析异常:路径不存在:dbfs:/databricks/python/lib/python3.7/site-packages/sampleFolder/data; 2022-01-01
- pytorch 中的自适应池是如何工作的? 2022-07-12
- python check_output 失败,退出状态为 1,但 Popen 适用于相同的命令 2022-01-01
- 如何在 python3 中将 OrderedDict 转换为常规字典 2022-01-01
- 使用Heroku上托管的Selenium登录Instagram时,找不到元素';用户名'; 2022-01-01