2015-09-28 81 views
0

我的模型:設置order_with_respect_to在Django的外鍵的外鍵訂購

Class A(Orderable, Slugged): 
    a = models.CharField(max_length=250, null=True, blank=True) 
    class Meta: 
     ordering = ("_order",) 

Class B(Orderable, Slugged): 
    a = models.ForeignKey(A, null=True, blank=True) 
    b = models.CharField(max_length=250, null=True, blank=True) 
    class Meta: 
     ordering = ("_order",) 
     order_with_respect_to = "a" 

Class C(Orderable, Slugged): 
    b = models.ForeignKey(B, null=True, blank=True) 
    c = models.CharField(max_length=250, null=True, blank=True) 
    class Meta: 
     ordering = ("_order",) 
     order_with_respect_to = "b__a" 

我怎樣才能實現這一目標? 我想要「C」類order_with_respect_to「A」類。 幫助將不勝感激。

回答

1

你可能嘗試從A.Meta繼承C.Meta

class C(Orderable, Slugged): 
    ... 
    class Meta(A.Meta): 
     pass # C.order_with_respect_to is equal to A.order_with_respect_to