Robel
Robel

Reputation: 37

how to combine queryset in django listview

I was using products.objects.all() to display all the values in the database but I want to do something more. I want to filter some specific data from the database using products.objects.filter()it worked but it is not working when I use this query in listview

coordinates = [1231,1231]
for i in coordinates:
   queryset = products.objects.filter(lat=i)

This code is returning only one value instead of multiple Thankyou.

Upvotes: 1

Views: 223

Answers (1)

neverwalkaloner
neverwalkaloner

Reputation: 47354

Instead of for loop you should use __in lookup to filter by multiple values:

queryset = products.objects.filter(lat__in=coordinates)

Upvotes: 2

Related Questions