Django: a spatial point-based m2m query returns an empty dict - but should contain the results

Hi people using stackoverflow,

I am confused with m2m requests in Django. I have a RadioStations model that lists radio stations around the continent (just a name and an accessible country) and has the following declaration:

class Station(models.Model):
    name = models.CharField(_('Station Name'), max_length=255
    reference = models.URLField(_('Link'), blank=True, verify_exists=True)  
    country = models.ManyToManyField(WorldBorder)

The WorldBorder class follows the example of GeoDjango here .

Now I would like to search all the stations in the USA. If I use:

s = Station.objects.filter(country__name__contains = "United States")

I get all the stations in the USA. However, if I am now performing a search with the user's location, for example.

pnt = fromstr('POINT(-96.876369 29.905320)', srid=4326)
s = Station.objects.filter(country__mpoly__contains = pnt)

the query result is empty (even if the point is in the US Is this related to how to make the m2m query? Why will the query results be empty? Is there any other way to access the m2m relationship?

!

+3
2

:

Stations WorldBorder, . Django attribute_set.all().

, , Point

country = WorldBorder.objects.get(mpoly__contains = ref_point)

Stations,

station_list = country.stations_set.all()

, set.all() get, . set.all() .

+1

, fromstr, geodjano. , Point.

from django.contrib.gis.geos import Point

pnt = Point(-96.876369, 29.905320)

, hte point?

+1

All Articles