django如何在FilteredSelectMultiple中显示用户全名 [英] django how to display users full name in FilteredSelectMultiple
本文介绍了django如何在FilteredSelectMultiple中显示用户全名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用FilteredSelectMultiple小部件来显示用户列表。目前它只显示用户名。我试图覆盖label_from_instance,如下所示,但似乎不起作用。如何显示用户的全名。
i am trying to use FilteredSelectMultiple widget to display list of users. currently it is displaying only username. I have tried to override the label_from_instance as seen below but it does not seem to work. how can it get to display users full name.
class UserMultipleChoiceField(FilteredSelectMultiple):
"""
Custom multiple select Feild with full name
"""
def label_from_instance(self, obj):
return "%s" % (obj.get_full_name())
class TicketForm(forms.Form):
cc_to = forms.ModelMultipleChoiceField(queryset=User.objects.filter(is_active=True).order_by('username'), widget=UserMultipleChoiceField("CC TO", is_stacked=True)
推荐答案
稍晚,但我认为可能会帮助人们尝试解决类似的问题: http://djangosnippets.org/snippets/1642/
A little late, but I think it might help people trying to solve a similar problem: http://djangosnippets.org/snippets/1642/
这篇关于django如何在FilteredSelectMultiple中显示用户全名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文