简体   繁体   English

django中的class Meta有什么用?

[英]What is the use of class Meta in django?

I have been using django and used class Meta: a lot of times, actually what is the use of it?我一直在用django ,用过class Meta:很多次了,到底有什么用呢?

for example, In django models例如,在 django models

class Accounts(models.Model):

   ---some code here--- 

   class Meta:
       ordering = [-1]

In django forms在 django forms

class AccountForm(forms.ModelForm):

   ---some code here--- 

   class Meta:
       fields = '__all__'

class Meta is basically the inner class. In Django, the use of the Meta class is simply to provide metadata to the ModelForm or the Model class. It is different from the metaclass of a Class in Python. class Meta is basically the inner class. In Django, the use of the Meta class is simply to provide metadata to the ModelForm or the Model class. It is different from the metaclass of a Class in Python.

class Meta用于更改模型的行为,例如排序、verbose_name 等。尽管它是可选的,是否包含在您的模型中。

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

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