Django Templates: Tree select option
Copy this code and paste it in your HTML
<select name="category" id="id_category"> {% for item in categories %}
{% ifequal item.parent_id 0 %}
{% for subitem in categories %}
{% ifequal subitem.parent_id item.id %}
<option value="{{ subitem.id }}">{{ subitem.name }}
</option> {% endifequal %}
{% endfor %}
{% endifequal %}
{% endfor %}
Report this snippet
Comments
Subscribe to comments