Reputation: 71
I'm trying to make a threaded commenting system based on django-mptt. The problem that I'm having is that the order of the comments cannot be changed according to their level.
What I am trying to achieve is a system in which "first level comments" are in ascending order based on submission date , while "nth level comments" (i.e. replies) are ordered in the opposite direction (check for example the youtube commenting system).
I have the order of insertion defined like this:
class MPTTMeta:
order_insertion_by=['-submit_date']
and the recursetree
templatetag
to render the tree with the comments.
Is there any solution to set the order of insertion (or display) based on the level of each comment?
Thanks
Upvotes: 0
Views: 463
Reputation: 71
Ok, I'll answer this question myself.
To get the "children" sorted in a order different from the "roots" I added:
childlist = list(node.get_children())
childlist.sort(key=lambda x: x.submit_date, reverse=False)
in the class RecurseTreeNode
that can be found in the mptt_tags.py
file.
Upvotes: 1