Add middle name display to autocomplete widget
from autocomplete_light import shortcuts as autocomplete_light
from django.contrib.auth.models import User, Group
+
class UserAutocomplete(autocomplete_light.AutocompleteModelBase):
search_fields = ['username', 'first_name', 'last_name']
split_words = True
@@ -10,15 +11,7 @@ class UserAutocomplete(autocomplete_light.AutocompleteModelBase):
return super(UserAutocomplete, self).choices_for_request()
def choice_label(self, choice):
- label = ""
-
- if choice.first_name:
- label += choice.first_name
-
- if choice.last_name:
- if choice.first_name:
- label += " "
- label += choice.last_name
+ label = " ".join([choice.first_name or "", choice.userprofile.middle_name or "", choice.last_name or ""])
if choice.userprofile.organization:
if choice.first_name or choice.last_name:
