mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Deprecated legacy GeoManager/GeoQuerySet methods
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import warnings
|
||||
|
||||
from django.contrib.gis.db.models.query import GeoQuerySet
|
||||
from django.db.models.manager import Manager
|
||||
from django.utils.deprecation import RemovedInDjango21Warning
|
||||
|
||||
|
||||
class GeoManager(Manager.from_queryset(GeoQuerySet)):
|
||||
@@ -9,3 +12,11 @@ class GeoManager(Manager.from_queryset(GeoQuerySet)):
|
||||
# so that geometry columns on Oracle and MySQL are selected
|
||||
# properly.
|
||||
use_for_related_fields = True
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
warnings.warn(
|
||||
"The GeoManager class is deprecated. Simply use a normal manager "
|
||||
"once you have replaced all calls to GeoQuerySet methods by annotations.",
|
||||
RemovedInDjango21Warning, stacklevel=2
|
||||
)
|
||||
super(GeoManager, self).__init__(*args, **kwargs)
|
||||
|
||||
@@ -15,7 +15,9 @@ from django.db.models.expressions import RawSQL
|
||||
from django.db.models.fields import Field
|
||||
from django.db.models.query import QuerySet
|
||||
from django.utils import six
|
||||
from django.utils.deprecation import RemovedInDjango20Warning
|
||||
from django.utils.deprecation import (
|
||||
RemovedInDjango20Warning, RemovedInDjango21Warning,
|
||||
)
|
||||
|
||||
|
||||
class GeoQuerySet(QuerySet):
|
||||
@@ -513,6 +515,11 @@ class GeoQuerySet(QuerySet):
|
||||
The name of the model attribute to attach the output of
|
||||
the spatial function to.
|
||||
"""
|
||||
warnings.warn(
|
||||
"The %s GeoQuerySet method is deprecated. See GeoDjango Functions "
|
||||
"documentation to find the expression-based replacement." % att,
|
||||
RemovedInDjango21Warning, stacklevel=2
|
||||
)
|
||||
# Default settings.
|
||||
settings.setdefault('desc', None)
|
||||
settings.setdefault('geom_args', ())
|
||||
|
||||
@@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.apps import apps
|
||||
from django.contrib.gis.db.models.fields import GeometryField
|
||||
from django.contrib.gis.db.models.functions import AsKML, Transform
|
||||
from django.contrib.gis.shortcuts import render_to_kml, render_to_kmz
|
||||
from django.core.exceptions import FieldDoesNotExist
|
||||
from django.db import DEFAULT_DB_ALIAS, connections
|
||||
@@ -31,15 +32,17 @@ def kml(request, label, model, field_name=None, compress=False, using=DEFAULT_DB
|
||||
|
||||
connection = connections[using]
|
||||
|
||||
if connection.features.has_kml_method:
|
||||
if connection.features.has_AsKML_function:
|
||||
# Database will take care of transformation.
|
||||
placemarks = klass._default_manager.using(using).kml(field_name=field_name)
|
||||
placemarks = klass._default_manager.using(using).annotate(kml=AsKML(field_name))
|
||||
else:
|
||||
# If the database offers no KML method, we use the `kml`
|
||||
# attribute of the lazy geometry instead.
|
||||
placemarks = []
|
||||
if connection.features.has_transform_method:
|
||||
qs = klass._default_manager.using(using).transform(4326, field_name=field_name)
|
||||
if connection.features.has_Transform_function:
|
||||
qs = klass._default_manager.using(using).annotate(
|
||||
**{'%s_4326' % field_name: Transform(field_name, 4326)})
|
||||
field_name += '_4326'
|
||||
else:
|
||||
qs = klass._default_manager.using(using).all()
|
||||
for mod in qs:
|
||||
|
||||
Reference in New Issue
Block a user