我的 django 代码已损坏并引发以下 AttributeError
:
AttributeError: 'GeoQuerySet' object has no attribute 'extent'
在我的代码中,我尝试在 django geoqueryset
上调用范围:
if raster and bbox:
self.extent = qs.extent()
我的 Django 版本当前是 1.10,最近从 Django 1.9 升级。
最佳答案
这是因为 Django deprecated自 Django 版本 1.8 起,GeoQuerySet
上的 extent
方法。可以使用 Extent
Aggregate Function 来修复此问题像这样:
from django.contrib.gis.db.models import Extent
# ...
if raster and bbox:
self.extent = qs.aggregate(Extent('geometry')).get(
'geometry__extent')
关于python - Django属性错误: 'GeoQuerySet' object has no attribute 'extent' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45051785/