Opened 16 years ago

Last modified 16 years ago

#9364 closed

Spatial queries don't work on inherited geometry fields — at Initial Version

Reported by: jbronn Owned by: jbronn
Component: GIS Version: 1.0
Severity: Keywords: gis inheritance
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In the following models TexasCity inherits from City:

from django.contrib.gis.db import models

class City(models.Model):
    name = models.CharField(max_length=30)
    point = models.PointField()
    objects = models.GeoManager()

    def __unicode__(self): return self.name

class TexasCity(City):
    tx_county = models.CharField(max_length=30)

    def __unicode__(self):
        return '%s (%s County)' % (self.name, self.tx_county)

When performing the following query:

In [4]: qs = TexasCity.objects.filter(point__distance_lte=(pnt, D(mi=5)))

This error is raised:

FieldError                                Traceback (most recent call last)

/Users/jbronn/geodjango/<ipython console> in <module>()

/Users/jbronn/hg/django/gis/django/db/models/manager.pyc in filter(self, *args, **kwargs)
    100 
    101     def filter(self, *args, **kwargs):
--> 102         return self.get_query_set().filter(*args, **kwargs)
    103 
    104     def complex_filter(self, *args, **kwargs):

/Users/jbronn/hg/django/gis/django/db/models/query.pyc in filter(self, *args, **kwargs)
    487         set.
    488         """
--> 489         return self._filter_or_exclude(False, *args, **kwargs)
    490 
    491     def exclude(self, *args, **kwargs):

/Users/jbronn/hg/django/gis/django/db/models/query.pyc in _filter_or_exclude(self, negate, *args, **kwargs)
    505             clone.query.add_q(~Q(*args, **kwargs))
    506         else:
--> 507             clone.query.add_q(Q(*args, **kwargs))
    508         return clone
    509 

/Users/jbronn/hg/django/gis/django/db/models/sql/query.pyc in add_q(self, q_object, used_aliases)
   1246                 else:
   1247                     self.add_filter(child, connector, q_object.negated,
-> 1248                             can_reuse=used_aliases)
   1249                 if connector == OR:
   1250                     # Aliases that were newly added or not used at all need to

/Users/jbronn/hg/django/gis/django/db/models/sql/query.pyc in add_filter(self, filter_expr, connector, negate, trim, can_reuse, process_extras)
   1121             field, target, opts, join_list, last, extra_filters = self.setup_joins(
   1122                     parts, opts, alias, True, allow_many, can_reuse=can_reuse,
-> 1123                     negate=negate, process_extras=process_extras)
   1124         except MultiJoin, e:
   1125             self.split_exclude(filter_expr, LOOKUP_SEP.join(parts[:e.level]),

/Users/jbronn/hg/django/gis/django/db/models/sql/query.pyc in setup_joins(self, names, opts, alias, dupe_multis, allow_many, allow_explicit_fk, can_reuse, negate, process_extras)
   1449 
   1450         if pos != len(names) - 1:
-> 1451             raise FieldError("Join on field %r not permitted." % name)
   1452 
   1453         return field, target, opts, joins, last, extra_filters

FieldError: Join on field 'point' not permitted.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top