0
我想在一个视图来检索以下数据:Django的查询许多一对多的关系
user_profile
有一个对一个加盟users
user_profile
有许多一对多加盟store
,通过stores
场
store
有一个一对多加入到targets
,通过targets.store
我可以做检索与用户相关联的所有专卖店:
user_profile = request.user.get_profile()
all_stores = user_profile.stores.all()
我想检索的是与用户ID user_profile
相关的所有目标,大概是通过all_stores
结果,但我不确定如何到达那里。
你是在找这个吗? https://docs.djangoproject.com/en/1.3/topics/db/queries/#spanning-multi-valued-relationships – 2011-06-03 20:19:41
@ S.Lott,是的,但我一直无法创建查询;我不知道我应该如何定义过滤器声明。 – urschrei 2011-06-03 20:23:42