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
an
Per: Is it possible to reference a property using Django's QuerySet.values_list?, avoiding values_list when not applicable, using a comprehension instead.
models.py:
class Person(models.Model):
first_name = models.CharField(max_length=32)
last_name = models.CharField(max_length=64)
def getPrintName(self):
return self.last_name + ", " + self.first_name
views.py:
data.form.fields['person'].choices = [(person.id, person.getPrintName()) for person in GetPersons()]