#22352: GeoQuerySet methods: support lookups on reversed o2o relationships as
field_name
----------------------------+------------------------------------
Reporter: pchiquet | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: master
Severity: Normal | Keywords: geodjango, GeoQuerySet
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------
GeoQuerySet methods, for example ''distance'', are performed on a given
geographic field of the model.
The geographic field to use can be specified thanks the '''field_name'''
argument. '''field_name''' can be a field directly in the model or a
lookup to a related field in another model (such as,
{{{'address__point'}}}). However '''lookups with reversed one to one
relation are not supported'''.
For example, with the following model:
{{{
#!python
class User(Model):
pass
class UserProfile(NamedModel):
user = models.OneToOneField(User)
point = models.PointField()
}}}
the following spatial operation on User fails:
{{{
#!python
User.objects.all().distance(Point(1,1),
field_name='userlocation__point')
}}}
and raises the following exception:
{{{
Traceback (most recent call last):
(...)
File "django/contrib/gis/db/models/query.py", line 104, in distance
return self._distance_attribute('distance', geom, **kwargs)
File "django/contrib/gis/db/models/query.py", line 593, in
_distance_attribute
procedure_args, geo_field = self._spatial_setup(func,
field_name=kwargs.get('field_name', None))
File "django/contrib/gis/db/models/query.py", line 466, in
_spatial_setup
raise TypeError('%s output only available on GeometryFields.' %
func)
TypeError: ST_Distance output only available on GeometryFields.
}}}
The lookup is supported only if the foreign key is in the Queryset model.
I think it would be nice to support reversed relations too.
--
Ticket URL: <https://code.djangoproject.com/ticket/22352>
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.6b44c50d08a7d3824a1b01f25881084d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.