1
I am creating a generic menu where a parent can have 1 child and so on (structure of a tree) and I have arisen a doubt of how to render the parents in a menu and when pass the mouse over the parent open laterally their children
Currently I only have this code that takes the parents and children all together, I would like to leave everything separated but I do not know which way to go.
def details(request,pk):
item = Item.objects.filter(fkmenu_id=pk)
template_name = 'menu/menu.html'
context = {
'items': item
}
return render(request,template_name,context)
I’m using mptt which is a lib to work with trees but so far nothing, in case someone has some way without the mptt also serves.
Okay, but that code doesn’t help much, put the class code
Item
, are persisted? in what way? how do you resolve the tree?– Sidon
In theory the node is the one that has the parent_id=null so in the template I can list by doing a for in the item and seeing if the item.parent_id is None but I wanted to also get this guy’s son.
– imp
I’m developing a Django app that uses this lib, in case I’m presenting a
api
tree-shaped, you can see the result here, on the Heroku and the implementation and description here at github– Sidon
In addition to developing the models, q vc has tried?
– Sidon
I managed to solve my problem by making a method to catch the children and dps made 1 inside another to render in the template
– imp
Solved the whole problem or still missing something?
– Sidon
I managed to solve my problem completely.
– imp
Create a recursive menu class that is called on each menu https://github.com/jazzband/django-simple-menu
– Alexandre Custodio