1

这是模型:

TYPE_CHOICES = (
('x','Some X'),
('y','Some Y'),
('z', 'Some Z'),
)

class MyModel(models.Model):
    some_type = models.CharField(max_length=1, choices=TYPE_CHOICES)
    desc = models.TextField()
    date_added = models.DateFimeField()

我想先获取记录,some_type='x'然后再获取其他记录(都按date_added每个“组”排序)

4

1 回答 1

0

使用order_by?

MyModel.objects.all().order_by("some_type", "date_added")
于 2012-08-08T21:25:25.660 回答