Question

I have in my databases a table called nodes and where i have parent child relationship and i am using

http://django-mptt.github.io/django-mptt/tutorial.html

for nodes

Now i can display all the nodes in the same and that is no problem.

But what i want is that i have folder like structure that if someone clicks of parent folder then i go to next view which will have its children only

and url will become

www.example.com/downloads/parentfolder

Then if user click on child folder1 then it shows its further children and url becomes

www.example.com/downloads/parentfolder/childfolder

how can i do that sort of thing

I want to do something like this

Django MPTT - how to query based on URL segments

But he didnt explain how he did it

Was it helpful?

Solution

You can do that with routing as you do in app which has normal django models from urls.py like this.

#urls.py

urlpatterns = patterns('',

    url(r'^downloads/(?P<parent_id>\d+)/$', ParentView.as_view(), name='parents_list'),
    url(r'^downloads/(?P<parent_id>\d+)/(?P<child_id>\d+)/$', ChildView.as_view(),
                                    name='childs_list'),
)

Write corresponding views, and you should be fine. Please bear in mind, I have used Class Based Views in above url example. Just write whatever type of views you are familiar with.

The first view will show parent or parents list from given parent id in url. The second view will show child inside parent given parent and child ids.

Edit

Looks like your requirement is a bit complex, I found better solution here Django-MPTT full path to child pages how to make?

I hope it will solve your problem :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top