2
Yep, you can use values()
queryset method.
YouModel.objects.filter(col2=something).values('col1')
UPDATE 1
If you want a raw representation, you need to use values_list
along flat=True
YouModel.objects.filter(title=showname).values_list('season',flat=True)
This returns
[01, 02, 03,....]
UPDATE 2
In your model seasonNumber
is a foreign key to a SeasonDetail instance, you are trying to assign a list. So, remove the value_list()
and get the first one.
episode_update.seasonNumber = SeasonDetail.objects.filter(title=showname)[0]
- [Answered ]-I am getting this error using django taggit "Can't call add with a non-instance manager"
0
With django version >=1.8: use the values_list
You can access list of column.
YourModel.objects.values_list('col1', 'col2')
You can also use:-
QuerySet.only()
and QuerySet.defer()
can be used to define which fields the ORM query should fetch and defer the others until the appropriate attributes on the models are accessed.
Source:stackexchange.com