I have a Person model and I am using a django form to edit another object with a foreign key to Person. The person model has first_name and last_name fields. I want to run a method to filter results for the drop down box of the foreign reference.
I am trying to use values_list() to override the form field options (choices property) like so:
data.form.fields['person'].choices = GetPersons().values_list('id', 'first_name')
GetPersons() just filters the Person class like
return Person.objects.filter(id__gt=1000)`
for example, so I only get people I want to show up. How can I use values_list() to return the concatenation of first_name and last_name without having to return a dictionary and splitting everything manually?
I have in mind 2 sugestions for you:
Sample:
and …
Sample:
Edited 2018
Concat is now available as database function: