过滤相关集中的相关集
我有以下模型结构:
parent Park
子仓库(带Park的外键,related_name = park_warehouses)
child child Issue(foreign key with Warehouse, related_name =Warehouse_issues)
现在我想通过获取每个公园建筑物的问题来过滤并获取公园的问题数量。
我已经尝试过这个 lambda,但它给了我空数组,即使我选择了这个公园的问题和建筑物:
filter(lambda x: park in park.park_warehouses.all(), Issue.objects.all())
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())
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Issue.objects.filter(warehouse__park=park)
Issue.objects.filter(warehouse__park=park)