Hay, I use MPTT to create some tree-like data from a model containing conversations, and I want them to be sorted by the “votes” field.
The model looks like this at the moment, very simple.
class Thread(MPTTModel):
message = models.CharField(max_length=100)
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
votes = models.IntegerField()
class MPTTMeta:
order_insertion_by=['votes']
As you can see, we have a message field and a parent FK, which is associated with the Thread model, and voices.
In my mind I have it
threads = Thread.tree.all()
data = {
'threads':threads
}
return render_to_response("show.html",data )
then in my template
{% load mptt_tags %}
<ul class="root">
{% recursetree d %}
<li>
{{ node.title }}
{% if not node.is_leaf_node %}
<ul class="children">
{{ children }}
</ul>
{% endif %}
</li>
{% endrecursetree %}
</ul>
However, the list displayed is a list of all threads. None of them are interconnected.
Any ideas?
dotty source
share