2

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.

Risadinha
  • 16,058
  • 2
  • 88
  • 91
RvdBerg
  • 195
  • 1
  • 11

1 Answers1

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')
RvdBerg
  • 195
  • 1
  • 11