将order_with_respect_to设置为django orderable中的外键的外键

时间:2015-09-28 05:22:07

标签: python 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 个答案:

答案 0 :(得分:1)

您可以尝试从C.Meta继承A.Meta

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