Django AttributeError: 'GeoQuerySet' object has no attribute 'extent'

时间:2017-07-12 08:00:06

标签: python django geo django-1.10

My django code is broken and raises the following AttributeError:

AttributeError: 'GeoQuerySet' object has no attribute 'extent'

In my code I try to call extent on a django geoqueryset:

    if raster and bbox:
        self.extent = qs.extent()

My Django version is currently 1.10 and has recently been upgraded from Django 1.9.

1 个答案:

答案 0 :(得分:4)

This is because Django deprecated the extent method on GeoQuerySets since Django version 1.8. This can be fixed using the Extent Aggregate Function like so:

from django.contrib.gis.db.models import Extent   

# ...

    if raster and bbox:
        self.extent = qs.aggregate(Extent('geometry')).get(
            'geometry__extent')