Django管理网站:添加用户页面如何工作(更多字段编辑)? [英] Django admin site: How does the Add User page work (more fields on edit)?

查看:122
本文介绍了Django管理网站:添加用户页面如何工作(更多字段编辑)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道他们如何在Django管理员网站的用户页面中显示更多的字段。
如果您创建一个新用户,您只需要填写一些基本字段,但如果您重新打开该用户(编辑模式),则会看到更多字段可以填写。

I was wondering how they made it possible to display more fields in the User page of the Django admin site. If you create a new User you only have some basic fields to fill in, but if you reopen that user (edit mode) then you see a lot more fields to fill in.

我试图实现这一点,我看了一下 add_form.html 模板,但我不能真正让我的头脑。我想我正在寻找一种基于文档编辑状态来指定不同的fields = []集合的方法。

I'm trying to achieve the same, I had a look at the add_form.html template but I can't really get my head around it. I guess I'm looking for a way of specifying different fields = [] sets based on the edit status of the document.

谢谢!

推荐答案

答案在于为用户模型注册的自定义管理类。它覆盖了 ModelAdmin 上的几种方法,并检查当前请求是否正在创建一个新的用户(其中例如,使用裸机表单类添加帐户)或编辑现有的(在这种情况下,显示完整的表单)。

The answer lies in the custom admin class registered for the User model. It overrides a couple of methods on ModelAdmin and checks to see whether the current request is creating a new User (in which case the bare-bones form class for adding accounts is used) or editing an existing one (in which case a full form is shown).

这篇关于Django管理网站:添加用户页面如何工作(更多字段编辑)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆