擅长:python、mysql、java
<p>你的模特长什么样?</p>
<p>对于您的疑问,<code>__in</code><a href="https://docs.djangoproject.com/en/1.5/ref/models/querysets/#in" rel="nofollow">does accept</a>过滤id。</p>
<p>对于当前代码,解决方案是:</p>
<pre><code>locations = Location.objects.filter(id__in=has_location.objects.filter(user=user).values('location_id'))
# if you just want the length of the locations, evaluate locations.count()
locations.count()
# if you want to iterate locations to access items afterwards
len(locations)
</code></pre>