[英]What is the use of class Meta in django?
我一直在用django
,用过class Meta:
很多次了,到底有什么用呢?
例如,在 django models
中
class Accounts(models.Model):
---some code here---
class Meta:
ordering = [-1]
在 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
用于更改模型的行为,例如排序、verbose_name 等。尽管它是可选的,是否包含在您的模型中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.