i'm trying implement simple file browser app using django-mptt
this models.py
class rootmptt(mpttmodel): name = models.charfield(max_length =255) parent = treeforeignkey('self',null=true,blank=true,related_name='children',db_index=true) class doc(models.model): file = models.filefield(upload_to=set_upload_path_mptt) belongs_to = models.foreignkey(rootmptt)
i'm trying show tree view in html using code tutorial section
{% load mptt_tags %} <ul> {% recursetree nodes %} <li> {{ node.name }} {% if not node.is_leaf_node %} <ul class="children"> {{ children }} </ul> {% endif %} </li> {% endrecursetree %} </ul>
i'm getting below error django
'rootmptt' object not support indexing
mainly because 'nodes' variable below
nodes = rootmptt.objects.get(pk=casenum)
if change to
nodes = rootmptt.objects.all()
the html rendered fine. need descendants of single node opposed root nodes.
i supposed can children getting get_children
method , manually show them in html. know if theres method using recursetree
recursetree
takes queryset or list of nodes, not single node. if want show 1 tree, make queryset tree in it:
nodes = rootmptt.objects.get(pk=casenum).get_descendants(include_self=true)
Comments
Post a Comment