【发布时间】:2013-03-16 05:11:36
【问题描述】:
我有名为“has_location”和“locations”的表。 'has_location' 有 user_has 和 location_id 以及它自己的 id,这是由 django 本身给出的。
'locations' 有更多列。
现在我想获取某个用户的所有位置。我所做的是..(user.id 是已知的):
users_locations_id = has_location.objects.filter(user_has__exact=user.id)
locations = Location.objects.filter(id__in=users_locations_id)
print len(locations)
但我通过这个print 得到0。我在数据库中有数据。但我感觉__in 不接受models id,是吗?
谢谢
【问题讨论】:
-
你能告诉我们这三个模型定义的相关部分吗?
-
@GarethRees,当然,但它们只是普通模型。我认为,这里的重点更多是关于我可以使用
__in的内容。
标签: python database django django-forms