我使用的是Django,它允许人们通过使用类Meta向类添加额外的参数。
class FooModel(models.Model):
...
class Meta:
...
我在Python的文档中唯一找到的东西是:
class FooMetaClass(type):
...
class FooClass:
__metaclass__ = FooMetaClass
然而,我不认为这是一回事。
我使用的是Django,它允许人们通过使用类Meta向类添加额外的参数。
class FooModel(models.Model):
...
class Meta:
...
我在Python的文档中唯一找到的东西是:
class FooMetaClass(type):
...
class FooClass:
__metaclass__ = FooMetaClass
然而,我不认为这是一回事。
当前回答
你在问两个不同的问题:
Meta inner class in Django models: This is just a class container with some options (metadata) attached to the model. It defines such things as available permissions, associated database table name, whether the model is abstract or not, singular and plural versions of the name etc. Short explanation is here: Django docs: Models: Meta options List of available meta options is here: Django docs: Model Meta options For latest version of Django: Django docs: Model Meta options Metaclass in Python: The best description is here: What are metaclasses in Python?
其他回答
Django的Model类专门处理一个名为Meta的属性,它是一个类。这不是一般的Python。
Python元类是完全不同的。
类Meta是代码逻辑中模型所在的位置。字段满足你的form.widgets。 因此,在Class Meta()下,您可以在模型的字段和您希望在表单中拥有的不同小部件之间创建链接。
你在问两个不同的问题:
Meta inner class in Django models: This is just a class container with some options (metadata) attached to the model. It defines such things as available permissions, associated database table name, whether the model is abstract or not, singular and plural versions of the name etc. Short explanation is here: Django docs: Models: Meta options List of available meta options is here: Django docs: Model Meta options For latest version of Django: Django docs: Model Meta options Metaclass in Python: The best description is here: What are metaclasses in Python?
内部元类文档:
django文档 模型元数据是“任何不是字段的东西”,比如排序选项(ordered)、数据库表名(db_table)或人类可读的单数和复数名称(verbose_name和verbose_name_复数)。没有一个是必需的,将类Meta添加到模型中是完全可选的。 https://docs.djangoproject.com/en/dev/topics/db/models/#meta-options
在Django中,它作为一个配置类,并将配置数据保存在一个地方!!