我的网站上有一个手风琴菜单,其中包含类别,子类别和文章,我希望能够查看用户单击了哪个类别,子类别和文章,并根据这些条件过滤我的模型,即类别中的子类别。
我首先尝试将手风琴的链接放在表单中并命名每个链接,但这只是弄乱了它在屏幕上的显示方式。
前端手风琴:
<!-- COllapsible sidebar -->
<div class="container-fluid">
<div class="row">
<div class="col-md-3 col-xs-1 " id="sidebar">
<div class="list-group panel">
<a href="#menu1" class="list-group-item collapsed" data-toggle="collapse" data-parent="#sidebar" aria-expanded="false"><i class="fa fa-dashboard"></i> <span class="hidden-sm-down">Item 1</span> </a>
<div class="collapse" id="menu1">
<a href="#menu1sub1" class="list-group-item" data-toggle="collapse" aria-expanded="false">Subitem 1 </a>
<div class="collapse" id="menu1sub1">
<a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 1 a</a>
<a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 2 b</a>
<a href="#menu1sub1sub1" class="list-group-item" data-toggle="collapse" aria-expanded="false">Subitem 3 c </a>
<div class="collapse" id="menu1sub1sub1">
<a href="#" class="list-group-item" data-parent="#menu1sub1sub1">Subitem 3 c.1</a>
<a href="#" class="list-group-item" data-parent="#menu1sub1sub1">Subitem 3 c.2</a>
<a href="#menu1sub1sub1sub1" class="list-group-item" data-toggle="collapse" aria-expanded="false">Subitem 3 c.3 </a>
<div class="collapse" id="menu1sub1sub1sub1">
<a href="#" class="list-group-item" data-parent="#menu1sub1sub1">Subitem 3 c.1</a>
<a href="#" class="list-group-item" data-parent="#menu1sub1sub1">Subitem 3 c.2</a>
</div>
</div>
<a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 4 d</a>
<a href="#menu1sub1sub2" class="list-group-item" data-toggle="collapse" aria-expanded="false">Subitem 5 e </a>
<div class="collapse" id="menu1sub1sub2">
<a href="#" class="list-group-item" data-parent="#menu1sub1sub2">Subitem 5 e.1</a>
<a href="#" class="list-group-item" data-parent="#menu1sub1sub2">Subitem 5 e.2</a>
</div>
</div>
<a href="#" class="list-group-item" data-parent="#menu1">Subitem 2</a>
<a href="#" class="list-group-item" data-parent="#menu1">Subitem 3</a>
</div>
</div>
</div>
</div>
</div>
任何获得我想要的建议或替代路线也受到赞赏,我所希望的是能够基于3个条件(即类别,子类别和文章)来从views.py过滤数据库。手风琴菜单中的分层步骤。
谢谢
答案 0 :(得分:0)
大概是单击子项后返回的视图,例如<a href="#" class="list-group-item" data-parent="#menu1sub1sub1">Subitem 3 c.1</a>
如果将其更改为<a href="{% url 'show-item' item.id %}" class="list-group-item" data-parent="#menu1sub1sub1">Subitem 3 c.1</a>
(假设您有合适的URL),则会显示该视图。
如果您特别需要上面的第1项,第1项,则可以
<a href="{% url 'view-name' item1 subitem1 item.id %}" class="list-group-item" data-parent="#menu1sub1sub1">Subitem 3 c.1</a>
您需要一个类似以下的网址:path('myview/<str:item>/<str:subitem>/<int:item_id>/', views.MyView.as_view(), name="view-name")