django model 中class meta

 class Meta:
        ordering = ['-num', 'length']
        verbose_name = 'name'
        verbose_name_plural = 'names'

 ordering:排序,(注意这里排序是要消耗数据库运算的), "-num"是按num降序排列,然后接着按length 升序排列。

verbose_name: 便于人识读的名字,单数形式

verbose_name_plural: 同上,但是是复数形式,如果不指定,系统默认是在后面加上“s”

 还有两人只读属性:label, label_lower

label: 表示对象名,实际是返回app_label.object_name 例如:app是 polls , model是Question, 那么回返“polls.Question”

label_lower ,返回小写模式“polls.question”

class Meta是可选的。

原文地址:https://www.cnblogs.com/Andy963/p/5783182.html