2016-11-07 52 views
0

是否可以使用參數創建抽象Django模型?像元meta類一樣?在Django中使用參數的抽象模型

class Parent(models.Model): 
    field1 = CharField(max_length=100, default=MY_STRING) 
    field2 = CharField(max_length=100, default=MY_STRING + ' lorem ipsum') 
    field3 = IntegerField(default=5) 

    class Meta: 
     abstract = True 

class Child(Parent(MY_STRING='abc')): 
    # now it should have: 
    # field1 with default value "abc" 
    # field2 with default value "abc lorem ipsum" 
    # field3 with default value 5 
+1

簡短的回答:沒有。除非你開始做一些與元類,類裝飾,monkeypatches等邪惡的巨型勝利,那就是...... –

回答