Wagh
Wagh

Reputation: 4306

set order_with_respect_to as foreign key of foreign key in django orderable

My models:

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"

How can i achive this? I want "C" class order_with_respect_to "A" class. Help will be appreciated.

Upvotes: 0

Views: 90

Answers (1)

Ozgur Vatansever
Ozgur Vatansever

Reputation: 52183

You might try to inherit C.Meta from A.Meta:

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

Upvotes: 1

Related Questions