python manage.py shell
{{{
In [1]: %paste
from django.contrib.gis.db.models.functions import Distance
from django.contrib.gis.geos import Point
from geotest.models import Test
point1 = Point(0, 0, srid=4326)
point2 = Point(0, 1, srid=4326)
Test.objects.create(point1=point1, point2=point2)
## -- End pasted text --
Out[1]: <Test: Test object>
In [2]: print Test.objects.annotate(dist=Distance('point1',
point2)).last().dist
111195.079735 m
In [3]: print Test.objects.annotate(dist=Distance(point1,
'point2')).last().dist
GEOS_ERROR: ParseException: Unknown type: 'POINT2'
---------------------------------------------------------------------------
ValueError Traceback (most recent call
last)
<ipython-input-3-aa91ca51a4df> in <module>()
----> 1 print Test.objects.annotate(dist=Distance(point1,
'point2')).last().dist
/home/sergey/dev/django/django/contrib/gis/db/models/functions.pyc in
__init__(self, expr1, expr2, spheroid, **extra)
239 self.spheroid = spheroid
240 expressions += (self._handle_param(spheroid,
'spheroid', bool),)
--> 241 super(Distance, self).__init__(*expressions, **extra)
242
243 def as_postgresql(self, compiler, connection):
/home/sergey/dev/django/django/contrib/gis/db/models/functions.pyc in
__init__(self, expression, geom, *expressions, **extra)
97 geom = GEOSGeometry(geom)
98 except Exception:
---> 99 raise ValueError("This function requires a
geometric parameter.")
100 if not geom.srid:
101 raise ValueError("Please provide a geometry attribute
with a defined SRID.")
ValueError: This function requires a geometric parameter.
In [4]: print Test.objects.annotate(dist=Distance('point1',
'point2')).last().dist
GEOS_ERROR: ParseException: Unknown type: 'POINT2'
---------------------------------------------------------------------------
ValueError Traceback (most recent call
last)
<ipython-input-4-177990c7d19a> in <module>()
----> 1 print Test.objects.annotate(dist=Distance('point1',
'point2')).last().dist
/home/sergey/dev/django/django/contrib/gis/db/models/functions.pyc in
__init__(self, expr1, expr2, spheroid, **extra)
239 self.spheroid = spheroid
240 expressions += (self._handle_param(spheroid,
'spheroid', bool),)
--> 241 super(Distance, self).__init__(*expressions, **extra)
242
243 def as_postgresql(self, compiler, connection):
/home/sergey/dev/django/django/contrib/gis/db/models/functions.pyc in
__init__(self, expression, geom, *expressions, **extra)
97 geom = GEOSGeometry(geom)
98 except Exception:
---> 99 raise ValueError("This function requires a
geometric parameter.")
100 if not geom.srid:
101 raise ValueError("Please provide a geometry attribute
with a defined SRID.")
ValueError: This function requires a geometric parameter.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25605>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
PR -- https://github.com/django/django/pull/5477
--
Ticket URL: <https://code.djangoproject.com/ticket/25605#comment:1>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/25605#comment:2>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/25605#comment:3>
* owner: nobody => sir-sigurd
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/25605#comment:4>
--
Ticket URL: <https://code.djangoproject.com/ticket/25605#comment:5>
* needs_better_patch: 1 => 0
Comment:
[https://github.com/django/django/pull/7670 new PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/25605#comment:6>
Comment (by Sergey Fedoseev):
I closed #27529 as a duplicate.
--
Ticket URL: <https://code.djangoproject.com/ticket/25605#comment:7>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/25605#comment:8>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"bde86ce9ae17ee52aa5be9b74b64422f5219530d" bde86ce9]:
{{{
#!CommitTicketReference repository=""
revision="bde86ce9ae17ee52aa5be9b74b64422f5219530d"
Fixed #25605 -- Made GIS DB functions accept geometric expressions, not
only values, in all positions.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25605#comment:8>