python - django - object filter logic -


i stuck in state: have locations table in db. , have rating table, contains rating of each location referencing id of each location.

now want first 5 locations , rating. have touch 2 tables now: locations , rating.

i did this:

all_locations = locations.objects.all()[:5] all_ratings = rating.objects.filter(of_location=all_locations.id) 

but seems wrong because all_locations queryset containing 5 locations , not 1 location, has 5 different ids. how can achieve goal?: take 5 locations , ratings of each of these 5 locations.

you can use in indicate value contained in list:

locations_ids = [location.id location in locations.objects.all()[:5]] all_ratings = rating.objects.filter(location__id__in=locations_ids) 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -