Saturday, June 30, 2012

Query with GeoDjango

Hello all. I'm wondering how to resolve this problem with a GeoDjango.This are my models:

from django.db import models
from django.contrib.gis.db import models as geomodels
from django.contrib.gis.geos import Point
from django.contrib.gis.measure import D

class Place(geomodels.Model):
    name = models.CharField(max_length=50)
    point = geomodels.PointField(null=True)
    objects = geomodels.GeoManager()

    def __unicode__(self):
        return u"%s the place" %

class Restaurant(models.Model):
    place = models.OneToOneField(Place, primary_key=True)
    serves_hot_dogs = models.BooleanField()
    serves_pizza = models.BooleanField()

    def __unicode__(self):
        return u"%s the restaurant" %


How can I get all Restaurants that serve pizza in a radio of 45km of a given (geolocation) point?
I'm trying something like:

pnt = Point(-34.5875015259, -58.6725006104)
Restaurant.objects.all().filter(place__point__distance_lte=(pnt, D(km=45)))

But it's not working:
Join on field 'point' not permitted. Did you misspell 'distance_lte' for the lookup type?

Any ideas?
Thanks in advance.

You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment