我在使用GeoDjango中的in
field lookup构建嵌套查询时遇到了问题。以下代码演示了此问题:
inner_qs = Footprint.objects.filter(geom__bboverlaps=bounding_box)
outer_qs = Footprint.objects.filter(pk__in=inner_qs)
outer_qs.count()
# error
使用上面的代码,会发生以下异常:
if (len(params) == 1 and params[0] == '' and lookup_type == 'exact'
File "../python2.6/site-packages/django/contrib/gis/db/backends/postgis/adapter.py", line 24, in __eq__
return (self.ewkb == other.ewkb) and (self.srid == other.srid)
AttributeError: 'str' object has no attribute 'ewkb'
只要内部查询包含空间过滤器,就会出现错误。以下嵌套查询工作正常:
inner_qs = Footprint.objects.filter(frequency__gt=1)
outer_qs = Footprint.objects.filter(pk__in=inner_qs)
outer_qs.count()
# ok
知道导致问题的原因是什么?