#25310: GeoManager's distance() method doesn't work with lookups that span
multiple
relationships
-----------------------------+----------------------------------
Reporter: seddonym | Owner: nobody
Type: New feature | Status: new
Component: GIS | Version: 1.8
Severity: Normal | Keywords: GeoManager, distance
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+----------------------------------
It is not currently possible to use the GeoQuerySet's distance() method to
make a query that spans multiple relationships. For example:
{{{
from django.contrib.gis.db import models
class Location(models.Model):
point = models.PointField()
objects = models.GeoManager()
class Office(models.Model):
location = models.ForeignKey(Location)
objects = models.GeoManager()
class Person(models.Model):
office = models.ForeignKey(Office)
objects = models.GeoManager()
}}}
It is possible to distance query the offices:
{{{
>>> point = Location.objects.first().point
>>> Office.objects.distance(point, field_name='location__point')
[<Office 1>, <Office 2>]
}}}
But not people:
{{{
>>> Person.objects.distance(point,
field_name='office__location__point')
*** TypeError: ST_Distance output only available on GeometryFields.
}}}
The reason for this is because of the way
`django.contrib.gis.db.models.query.GeoQuerySet._geo_field()`
performs the check - it just looks for fields that are in the model
class's `._meta.fields`.
(Incidentally, I'm not sure this is the correct error message - actually
it hasn't found the field at all, and should probably say so.)
--
Ticket URL: <https://code.djangoproject.com/ticket/25310>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.8f7117aaa9f8a9bf6a8c56a6e0e6e1bc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.