25👍
✅
full name is not a field in the django model, it is not possible.
you can use list comprehensions
[person.fullname for person in Person.objects.all() ]
👤zaca
21👍
values_list
can only work on fields retrieved directly from the database. As zaca notes, you’ll need a list comprehension on the actual queryset:
[person.fullname for person in Person.objects.all()]
Don’t over-use values_list
. It’s just meant as a means of limiting the db query, for when you know you’ll only ever need those particular fields. For almost all uses, getting the standard queryset is efficient enough.
- [Django]-Is there a simple way to get group names of a user in django
- [Django]-Remove "add another" in Django admin screen
- [Django]-Adding links to full change forms for inline items in django admin?
9👍
Full name is not a field in the Django model, so you can use annotation like:
people = Person.objects.annotate(
full_name=Concat(
'first_name',
Value(' '),
'last_name'
)
).values_list('full_name')
- [Django]-ValueError – Cannot assign: must be an instance
- [Django]-How do you Require Login for Media Files in Django
- [Django]-Passing data from Django to D3
Source:stackexchange.com