2015-09-28 82 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