我的其中一个表格中包含以下内容:
self.fields['advisor'].queryset = User.objects.filter(groups__name='advisor')
唯一的问题是它在下拉框中显示用户名。我想做的是先显示 first_name,然后显示 last_name 以使其更易于阅读。
有什么想法吗?
请您参考如下方法:
ModelChoiceField 有一个 label_from_instance 方法,可以在子类中更改该方法以使用模型 __unicode__ 方法以外的方法。 https://docs.djangoproject.com/en/1.3/ref/forms/fields/#django.forms.ModelChoiceField.empty_label
