Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » possible bug in joining on a geo field [RSS Feed]

#1 Oct. 23, 2010 18:08:11

Miguel A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

possible bug in joining on a geo field


Hi everyone,

I'm trying to do a join on geo field. I have two models like these ones
(simplified):

from django.contrib.gis.db import models
class Spot(models.Model):
point = models.PointField(spatial_index = True, srid = 4326, geography =
True)
objects = models.GeoManager()

from django.db import models
class Item(models.Model):
location = models.ForeignKey(Spot)
description = models.CharField(max_length=100)

I'm trying to execute this query:

from django.contrib.gis.geos import Point
point = Point(4, 5)
Item.objects.filter(location__point__distance_lte = (point, D(km=10)))

And I'm getting:

FieldError: Join on field 'point' not permitted. Did you misspell
'distance_lte' for the lookup type?

is this a bug? should I report it in a ticket? am I doing anything wrong?

Thanks, regards
Miguel Araujo

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Oct. 23, 2010 18:10:49

Karen T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

possible bug in joining on a geo field


On Sat, Oct 23, 2010 at 1:07 PM, Miguel Araujo <muchoch...@gmail.com> wrote:

> Item.objects.filter(location__point__distance_lte = (point, D(km=10)))
>

Looks like you are missing an underscore in distance__lte

Karen
--http://tracey.org/kmt/--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Oct. 23, 2010 18:29:08

Miguel A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

possible bug in joining on a geo field


Thanks Karen, you are right. But I missed the underscore for sending this,
although I was trying here with double underscore:

So If I do it right:

Item.objects.filter(location__point__distance__lte = (point, D(km=10)))

I get:

FieldError: Join on field 'point' not permitted. Did you misspell 'distance'
for the lookup type?

So it's still not working.

Regards,
Miguel Araujo

2010/10/23 Karen Tracey <kmtra...@gmail.com>

> On Sat, Oct 23, 2010 at 1:07 PM, Miguel Araujo <muchoch...@gmail.com>wrote:
>
>> Item.objects.filter(location__point__distance_lte = (point, D(km=10)))
>>
>
> Looks like you are missing an underscore in distance__lte
>
> Karen
> --
>http://tracey.org/kmt/>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Oct. 25, 2010 10:05:13

Miguel A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

possible bug in joining on a geo field


Should I report it? who should I contact? Anyone can confirm this is a bug?

2010/10/23 Miguel Araujo <muchoch...@gmail.com>

> Thanks Karen, you are right. But I missed the underscore for sending this,
> although I was trying here with double underscore:
>
> So If I do it right:
>
> Item.objects.filter(location__point__distance__lte = (point, D(km=10)))
>
> I get:
>
> FieldError: Join on field 'point' not permitted. Did you misspell
> 'distance' for the lookup type?
>
> So it's still not working.
>
> Regards,
> Miguel Araujo
>
> 2010/10/23 Karen Tracey <kmtra...@gmail.com>
>
> On Sat, Oct 23, 2010 at 1:07 PM, Miguel Araujo <muchoch...@gmail.com>wrote:
>>
>>> Item.objects.filter(location__point__distance_lte = (point, D(km=10)))
>>>
>>
>> Looks like you are missing an underscore in distance__lte
>>
>> Karen
>> --
>>http://tracey.org/kmt/>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
>> .
>> For more options, visit this group at
>>http://groups.google.com/group/django-users?hl=en.
>>
>
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 Dec. 18, 2010 23:42:17

f.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

possible bug in joining on a geo field


I have discovered the exact same issue.


class Apt(Model):

geo = models.PointField(srid=4326,editable=False,default=Point(0,0))
bldg = models.ForeignKey(Bldg,null=True)


class AptStatus(Model):

apt = models.ForeignKey(Apt)

class DP_5cbc61d6(Model):

apt = models.ForeignKey(Apt)


# works fine of course
Apt.objects.filter(geo__within=box)

# neither foreign key works
AptStatus.objects.filter(apt__geo__within=box)
FieldError: Join on field 'geo' not permitted. Did you misspell 'within' for
the lookup type?

DP_5cbc61d6.objects.filter(apt__geo__within=box)
FieldError: Join on field 'geo' not permitted. Did you misspell 'within' for
the lookup type?


# but curiously this one does work, joining to a nullable foreign key


class Bldg(Model):

geo = models.PointField(srid=4326,editable=False,default=Point(0,0))


Apt.objects.filter(bldg__geo__within=box)

I submitted a ticket.http://code.djangoproject.com/ticket/14922--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#6 Dec. 19, 2010 18:57:01

f.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

possible bug in joining on a geo field


ah no, now I get it: geo queries requires a GeoManager. so even though the
starting class does not have gis fields, it needs a GeoManager in order to
build queries addressing fields on the other model.

I'm not sure what should happen, the error messaging is very misleading, but
once you know the reason I supposed it makes sense.

I guess if the join is happening on another model's fields then the manager
for that other model should be used. otherwise its force me to add a geo
manager to a class that has no geo fields, but that's not too bad.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » possible bug in joining on a geo field [RSS Feed]

Board footer

Moderator control

Enjoy the 13th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support