voxoft
voxoft

Reputation: 67

Filter related set in a related set

I have the following structure of models :

parent Park
child Warehouse(foreign key with Park, related_name = park_warehouses)
child child Issue(foreign key with Warehouse, related_name = warehouse_issues)

now I'd like to filter and get amount of Issues for Park by getting issues of each park's building.

I've tried this lambda but it gives me empty array even though I have both issues and buildings for this park selected :

filter(lambda x: park in park.park_warehouses.all(), Issue.objects.all())

Upvotes: 0

Views: 134

Answers (1)

DrTyrsa
DrTyrsa

Reputation: 31951

Issue.objects.filter(warehouse__park=park)

Upvotes: 1

Related Questions