5

I'm trying to use the mptt library for a simple nested comment system.

My Model

class Comment(MPTTModel):
    event = models.ForeignKey(Event)
    author = models.CharField(max_length=60)
    comment = models.TextField()
    added  = models.DateTimeField(default=timezone.now())
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
    class MPTTMeta:order_insertion_by = ['added']

Right now, if I use {% recursetree nodes %} template tag, it displays the nodes in ascending time based on 'added'. I want to display the root notes by descending time, the newest comments first. I tried sorting nodes so it is descending, but recursetree does not follow that order. Is there a way to specify a descending ordering? I tried ['-added'], but it does not work.

heifetz
  • 353
  • 1
  • 3
  • 6

1 Answers1

0

Download updated version of django-mptt from github - It will allow you to use descending order the way you wanted. For example:

class Comment(MPTTModel):
    event = models.ForeignKey(Event)
    author = models.CharField(max_length=60)
    comment = models.TextField()
    added  = models.DateTimeField(default=timezone.now())
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children')

    class MPTTMeta:
        order_insertion_by = ['-added']
Lukasz Koziara
  • 4,274
  • 5
  • 32
  • 43