在Django orderab中,将顺序\u与\u相关的\u设置为外键的外键

2024-09-29 23:31:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我的模型:

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”级秩序,尊重“A”级。 我们将不胜感激。你知道吗


Tags: truemodelsordernulllengthmaxmetaclass
1条回答
网友
1楼 · 发布于 2024-09-29 23:31:58

您可以尝试从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

相关问题 更多 >

    热门问题