如何在 peewee meta 中使用默认排序 class
How to use default sorting in peewee meta class
我正在使用 Peewee ORM。
我有一个 class 这样的:
class Sample(PMBaseModel):
id = peewee.PrimaryKeyField()
location = peewee.CharField(max_length=255)
position = peewee.IntegerField()
class Meta:
db_table = 'sample'
如何使用 Meta Class
设置默认排序并定义订单类型?
按照此说明操作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']
我找到了答案,感谢@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 排序。
我正在使用 Peewee ORM。
我有一个 class 这样的:
class Sample(PMBaseModel):
id = peewee.PrimaryKeyField()
location = peewee.CharField(max_length=255)
position = peewee.IntegerField()
class Meta:
db_table = 'sample'
如何使用 Meta Class
设置默认排序并定义订单类型?
按照此说明操作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']
我找到了答案,感谢@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 排序。