I have this code:
>>> d = HotelCheck.objects.filter(client=1,date_booked='2012-02-27').distinct('product').values('product')['product_id']
>>> d
[{'product': 6}, {'product': 1}]
And I just want the output to be 1 and 6.
So I tried this:
>>> d = HotelCheck.objects.filter(client=1,date_booked='2012-02-27').distinct('product').values('product')['product_id']
But I got this error:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 153, in __getitem__
raise TypeError
TypeError
Does anyone have any ideas on how I can show only the values (6 and 1,) of the product?
You’re looking for
values_list. Pass it theflatargument, and you’ll directly get a list of product ids. Your lookup is failing becauseValuesQuerySetcan only be sliced or integer indexed.