我使用的是Peewee ORM。
我有一个这样的课程:
class Sample(PMBaseModel):
id = peewee.PrimaryKeyField()
location = peewee.CharField(max_length=255)
position = peewee.IntegerField()
class Meta:
db_table = 'sample'
如何使用Meta Class
设置默认排序并定义订单类型?
答案 0 :(得分:2)
我找到了答案,感谢@giaosudau。
class Sample(PMBaseModel):
id = peewee.PrimaryKeyField()
location = peewee.CharField(max_length=255)
position = peewee.IntegerField()
class Meta:
db_table = 'sample'
order_by = ['-location']
如果使用' - '在order_by
部分的第一个字段名称中,peewee执行DESC对提交的排序。
答案 1 :(得分:1)
按照此说明https://peewee.readthedocs.org/en/latest/peewee/models.html#model-options
我们使用order_by
字段列表用于默认排序
然后
class Sample(PMBaseModel):
id = peewee.PrimaryKeyField()
location = peewee.CharField(max_length=255)
position = peewee.IntegerField()
class Meta:
db_table = 'sample'
order_by = ['location']