Python超级Meta Class来自另一个类

时间:2014-09-30 17:14:56

标签: python django python-2.7

在Test2课程中,我想在其Meta类中包含模型和字段。这可能吗?怎么样?这就是我试过的......

我有一个混音:

class Test1(object):
        pass
    class Meta:
        fields = ("url",)

class Test2(Test1):
        pass
    class Meta:
        super(Meta) <=== does not work
        models= test

1 个答案:

答案 0 :(得分:7)

您的答案可以在Django Documentation

中找到

from django.db import models

class CommonInfo(models.Model):
    # ...
    class Meta:
        abstract = True
        ordering = ['name']

class Student(CommonInfo):
    # ...
    class Meta(CommonInfo.Meta):
        db_table = 'student_info'