mysql - Displaying N - parent N - Child menu Django -


here stucked piece of code

let me explain want display items this

chocolate     hot chocolate     white chocolate         salted caramel hot chocolate     peppermint hot chocolate espresso beverage     caffe americano     caffe latte        caffe moche     cappuccino frappuccino            b           c               d 

here using django view , template displaying

in mysql table have inserted these records 4 column 1.id 2.name 3.slug 4.parent

in display above

 eg  chocolate  id 1  , parent 0        hot chocolate  id 2 , parent 1        white chocolate  id 3 , parent 1        salted caramel hot chocolate id 4 , parent 3        espresso beverage  id 6 , parent 0 

hope understood

my html code

 {% cat in user %}   {% if cat.parent = 0%}   <ul id="listmenu" style="list-style-type:none; margin-left:-50">          <li class="listparent"><p style="font-size:15px;"><a href="#" style="text-decoration: none;color: black;">{{cat.name}}<br></a></p></li>      {% cat1 in user %}     {% if cat1.parent = cat.id%}      <ul class="menuitems" style="list-style-type:none;">        <li class="listchild"> <p class="tier1" style="font-size:15px;"><a href="#" style="text-decoration: none;color: black;" >{{cat1.name}}<br></a></p></li>        </ul>       {%endif%}        {% endfor %}         </ul>       {%endif%}        {% endfor %} 

and view

error = 50 @login_required  def categories(request):      context = requestcontext(request)      user = categories.objects.all()      if request.method == 'post':            catform = categoryform(data=request.post)            post_values = request.post.copy()             post_values['userid'] = request.user.id            post_values['createdby'] = request.user.id            post_values['modifiedby'] = request.user.id            catform = categoryform(post_values)                    if catform.is_valid():                  is_valid = true               profile = catform.save(commit=false)                  profile.save()                  registered = true                  messages.add_message(request, error, 'category added.')              else:                  messages.add_message(request, messages.info, 'invalid input check slug or order.')      else:          catform = categoryform()      paginator = paginator(user, 20)           try: page = int(request.get.get("page", '1'))      except valueerror: page = 1       try:          user = paginator.page(page)      except (invalidpage, emptypage):          user = paginator.page(paginator.num_pages)      return render_to_response('myapp/categories.html',{'catform':catform,'user':user},context) 

please suggest me logic required output

with above code achieve 1 parent 1 child not n parent n child

thanks in advance :_)


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -