Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango Displaying Menu/Sub Menu
    primarykey
    data
    text
    <p>I am trying to displaying Menu and Sub Menu in table format like</p> <pre><code>Menu1 Menu2 SubMenu1 SubMenu2 SubMenu3 Menu3 SubMenu4 SubMenu5 SubMenu6 Menu4 </code></pre> <p>So far, I was able to come up with below code but its not showing any record.</p> <p>Views.py</p> <pre><code>def getCompleteMenuList(): return Menu.objects.getMenuListing(id) #mainMenuObj=Menu.objects.getMenuListing(id) return render_to_response('manageMenu.html', {'title': menu_title,'name':name,'mainMenu':getCompleteMenuList,},context_instance=RequestContext(request)) </code></pre> <p>Models.py</p> <pre><code>def getMenuListing(self, id): mainMenus = self.filter(parent_menu=0,business=id).order_by('order') result = [] menus = [] for menu in mainMenus: menus.append(menu) submenu = self.filter(parent_menu=menu,business=id).order_by('order') if submenu.exists(): result.append(submenu) return dict(zip(menus, result)) </code></pre> <p>template.html</p> <pre><code>{% with mainMenu.items as pop_menus %} {% for key, value in pop_menus %} display main menu rows {% for data in value %} display sub menu rows {% endfor %} {% endfor %} {% endwith %} </code></pre> <p>Current Situation I have 5 rows in table with 4 as parent_menu =0 and 1 as parent_menu = 1 (which exists).</p> <p>When I try to print mainMenus its show 4 menu object.</p> <pre><code>&lt; Menu: Menu object &gt;, &lt; Menu: Menu object &gt;, &lt; Menu: Menu object &gt;, &lt; Menu: Menu object &gt; </code></pre> <p>But when I print menu inside for loop it only print 1 Menu object Menu object</p> <p>Can you please advise what I am doing wrong or is there any other way to achieve same thing?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload