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.