[英]Django query across many-to-many relationship
我正在嘗試在視圖中檢索以下數據:
user_profile
與users
一對一連接
user_profile
有一個多對多的連接到store
,通過stores
字段
store
通過targets.store
與targets
進行一對多連接
我可以通過執行以下操作檢索與用戶關聯的所有商店:
user_profile = request.user.get_profile()
all_stores = user_profile.stores.all()
我想檢索的是與user_profile
的用戶 ID 關聯的所有目標,大概是通過all_stores
結果,但我不知道如何到達那里。
Target.objects.filter( store__user_profile__user=request.user )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.