我有以下模型:
class Stop(models.Model):
name = models.CharField(max_length=50)
point = models.PointField()
objects = models.GeoManager()
我希望你能帮我将我的站点按照从北到南的顺序排序。请问应该怎么做?
Stop.objects.order_by('point')
这条命令会将它们按照从西到东的顺序排序。谢谢。
以下是完整的模型内容:
from django.contrib.gis.db import models
from django.core.urlresolvers import reverse
class Stop(models.Model):
gtfs_stop_id = models.IntegerField(db_index=True, unique=True)
name = models.CharField(max_length=50)
point = models.PointField()
parkings = models.GeometryCollectionField(null=True, blank=True)
objects = models.GeoManager()
def get_absolute_url(self):
return reverse('core:stop', args=(self.id,))
def __str__(self):
return self.name
Stop.objects.order_by('point__x')/Stop.objects.order_by('-point__x')
或者Stop.objects.order_by('point__y')/Stop.objects.order_by('-point__y')
。 - trinchet