[英]How to use default sorting in peewee meta class
我正在使用Peewee ORM。
我有這樣的課:
class Sample(PMBaseModel):
id = peewee.PrimaryKeyField()
location = peewee.CharField(max_length=255)
position = peewee.IntegerField()
class Meta:
db_table = 'sample'
如何使用Meta Class
設置默認排序並定義訂單類型?
我感謝@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排序。
請遵循以下說明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']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.