简体   繁体   English

如何在不扩展用户 Model 的 Django ModelForm 中自定义默认用户 Model 的用户名字段的显示?

[英]How do I customize the display of username field of default User Model in Django ModelForm without extending User Model?

I have a default User Model, with which I have connected a ModelForm .我有一个默认User Model,我已经连接了一个ModelForm In the ModelForm , I am accessing the username field of the default User Model.ModelForm中,我正在访问默认username Model 的User名字段。 It works fine as usual, it shows the username (s) of the users.它像往常一样工作正常,它显示了username的用户名。 But I don't want it to just show username, instead I want to show the custom content of each user.但我不希望它只显示用户名,而是我想显示每个用户的自定义内容。 I want to show first_name , last_name and username of the user in the following format: {first_name last_name - (username)}我想以以下格式显示用户的first_namelast_nameusername{first_name last_name - (username)}

Current display of the username filed: username名字段的当前显示:

user1
user2
user3
user4
#
#
#

Desired display of the `username field:所需的“用户名”字段显示:

John Doe - (user1)
Doni Marquart - (user2)
Geoff Roberts - (user3)
Alice Woods - (user4)
#
#
# 

Does anyone know how can I accomplish it without extending the default User Model?有谁知道如何在不扩展默认用户 Model 的情况下完成它? Thanks谢谢

in you'r templates:在你的模板中:

{% for user in user_list %}
    {{ user.first_name }}
    {{ user.last_name }}
<!--  ....    --/>


{% endfor %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM