1

I have the following two models.

class Category(MPTTModel):
    name=models.CharField(max_length=75,null=False,blank=False, unique=True)
    parent=TreeForeignKey('self', null=True, blank=True, related_name='children')

and

class ProductGroup(models.Model):
    name = models.CharField(max_length=30,null=False, blank=False)
    category=TreeForeignKey('category.Category', null=False,blank=False)

I have set an order for the categories through the admin panel.

I need to get the ProductGroup objects sorted in the same order through its ListView sub class.

I have tried,

class ProductGroupList(ListView):
    model=ProductGroup
    ordering = ['category']

but this lists the objects in the order of id of Categories.

Is there a way to specify the order specified in the mptt tree?

Thanks.

art
  • 1,358
  • 1
  • 10
  • 24
  • Check this link https://stackoverflow.com/questions/7937130/django-mptt-order it can help you – attin83 Jul 20 '17 at 15:25
  • I had a look at that thread, but it talks about the ordering of objects of the same class. Thanks. – art Jul 21 '17 at 06:20

0 Answers0