简体   繁体   English

class Meta 中的“Verbose_name”和“Ordering”是什么? 请在 django 中解释一下 Meta Class

[英]What is "Verbose_name" and "Ordering" in class Meta? And please explain a little about Meta Class in django

''' from django.db import models import uuid class Book(models.Model): name=models.CharField(max_length=100) isbn=models.UUIDField(default=uuid.uuid4, primary_key=True) writer=models.CharField(max_length=100) ''' 来自 django.db 导入模型导入 uuid class Book(models.Model): name=models.CharField(max_length=100) isbn=models.UUIDField(default=uuid.uuid4, primary_key=True) writer=models.CharField (最大长度=100)

    class Meta:
        ordering=['name']
        ordering='User MetaData'''

With class Meta you can give to your model metata such as database table name or ordering options.使用 class 元数据,您可以为 model 元数据提供数据库表名或排序选项等元数据。 You can check it out in documentation您可以在文档中查看

By using "verbose_name" in class Meta you can specify human-readable name for singular object. Documentation通过在 class Meta 中使用“verbose_name”,您可以为单数 object 指定人类可读的名称。 文档

By using 'ordering' in class Meta you can specify in which order you will get list of objects.通过使用 class Meta 中的“排序”,您可以指定获取对象列表的顺序。 By ['-field_name'] you specify descending order.通过 ['-field_name'] 指定降序。 By ['field_name'] you specify ascending order.通过 ['field_name'] 您可以指定升序。 You can make ordering by several fields: ordering = ['field1', 'field2'].您可以按多个字段进行排序:ordering = ['field1', 'field2']。 Documentation 文档

1.Model Meta is basically used to change the behavior of your model fields like changing order options,verbose_name and lot of other options. 1.Model Meta 基本上用于改变模型字段的行为,例如更改订单选项、verbose_name 和许多其他选项。 It's completely optional to add Meta class in your model.在模型中添加 Meta 类是完全可选的。

2.Verbose_name is a human-readable name for the field. 2.Verbose_name 是字段的人类可读名称。

3.Ordering takes a list of string values, which are model fields. 3.Ordering 接受一个字符串值列表,它们是模型字段。 It's used to define the ordering of objects of a model.它用于定义模型对象的顺序。 When the objects of this model are retrieved, they will be present in this ordering.当检索到此模型的对象时,它们将按此顺序出现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM