Change Django ModelChoiceField to show users' full names rather than usernames

后端 未结 5 1098
不知归路
不知归路 2020-11-30 01:31

I have a form in my Django app (not in admin) that allows staff members to select a user from a dropdown.

forms.ModelChoiceField(queryset = User.objects.filt         


        
5条回答
  •  旧巷少年郎
    2020-11-30 01:42

    You can override the field with a custom ModelChoiceField and change the label_from_instance function to return get_full_name instead. See the docs for ModelChoiceField: http://docs.djangoproject.com/en/1.2/ref/forms/fields/#modelchoicefield

提交回复
热议问题