On Jul 29, 2010, at 2:58 PM, Alexandre González wrote: > Hi! > > I'm searching near people in my app. I'm doing it a this way: > > 37 people = Person.objects.all().exclude(user=request.user) > 38 > 39 near_people = list() > 40 for person in people: > 41 if self.is_near(me.coordinates, person.coordinates): > near_people.append(person) > > Now, I'm getting all the the Person objects. This is a inefficient way. > > The coordinates are latitude/longitude coordinates, so I think in test the > variation and get only latitude +/- 1 and longitude +/- 1 and after this, do > the test exactly (the funcion is_near). > > But instead this, can I "draw" a circle and search only Person objects inside > it?
I'm not sure what database you are using, but if you are using PostgreSQL, it has built-in geometric operators specifically for this kind of thing. You might have to drop down into SQL, but in 1.2, that's nice and easy. The PostgreSQL documentation on this is at: http://www.postgresql.org/docs/8.4/interactive/datatype-geometric.html -- -- Christophe Pettus x...@thebuild.com -- 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 at http://groups.google.com/group/django-users?hl=en.