78
QuerySet.values()
or QuerySet.values_list()
, e.g.:
Entry.objects.values('first_name')
24
If you want a list of only the values, use:
Entry.objects.values_list('first_name', flat=True)
- [Django]-Make the first letter uppercase inside a django template
- [Django]-Django FileField: How to return filename only (in template)
- [Django]-Get current user in Model Serializer
3
To only get a column’s values from the table but still return an object of that model, use only
:
record = Entry.objects.only('first_name')
This will defer all other columns from the model but you can still access them all normally.
record.first_name # already retrieved
record.last_name # retrieved on call
- [Django]-What's the point of Django's collectstatic?
- [Django]-How to get the ID of a just created record in Django?
- [Django]-What is the path that Django uses for locating and loading templates?
Source:stackexchange.com