﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
25310	GeoManager's distance() method doesn't work with lookups that span multiple relationships	David Seddon	nobody	"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.)"	New feature	closed	GIS	1.8	Normal	wontfix	GeoManager, distance		Unreviewed	0	0	0	0	0	0
