更改 Django admin 的用户 ModelAdmin
如何覆盖用户的管理模型?我以为这会起作用,但事实并非如此?
class UserAdmin(admin.ModelAdmin):
list_display = ('email', 'first_name', 'last_name')
list_filter = ('is_staff', 'is_superuser')
admin.site.register(User, UserAdmin)
我不想覆盖模板,只需更改显示的字段和内容即可。订购。
请问解决方案?
How do you override the admin model for Users? I thought this would work but it doesn't?
class UserAdmin(admin.ModelAdmin):
list_display = ('email', 'first_name', 'last_name')
list_filter = ('is_staff', 'is_superuser')
admin.site.register(User, UserAdmin)
I'm not looking to override the template, just change the displayed fields & ordering.
Solutions please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须首先取消注册
用户
:也许这个问题对您来说也很有趣:Customizing an Admin form in Django while also using自动发现
You have to unregister
User
first:Maybe this question is also interesting for you: Customizing an Admin form in Django while also using autodiscover
使用 Django 3+ 进行了更新测试,
因此您不会丢失密码加密和表单本身等数据,请执行下面的导入
定义 AdminCustom 类作为示例,并使用您想要的选项进行自定义,覆盖默认值。
最后,按照提到的例子进行操作
Update tested with Django 3+
So you don't lose data like password encryption and the form itself, perform the import below
Define an AdminCustom class as the example and customize with the options you want, overriding the default.
And in the end, follow the example mentioned
正如@haifeng-zhang 在评论中指出的那样,扩展默认的 UserAdmin 是很有用的。
有关此内容的官方文档可以在这里找到:
https://docs.djangoproject .com/en/dev/topics/auth/customizing/#extending-the-existing-user-model
As pointed by @haifeng-zhang in the comments, it is useful to extend the default UserAdmin instead.
The official documentation about this can be found here:
https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-the-existing-user-model