【问题标题】:Python super on Meta Class from another classPython super on Meta Class 来自另一个类
【发布时间】:2014-11-25 09:54:53
【问题描述】:

在 Test2 类中,我想在其 Meta 类中包含模型和字段。这可能吗?如何?这是我尝试过的......

我有一个混合:

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

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

【问题讨论】:

    标签: python django python-2.7


    【解决方案1】:

    你的答案可以在Django Documentation找到

    I.E.

    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'
    

    【讨论】:

    猜你喜欢
    • 2021-08-21
    • 1970-01-01
    • 2011-11-20
    • 2020-12-13
    • 1970-01-01
    • 2013-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多