Django Templates: Tree select option


/ Published in: HTML
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <select name="category" id="id_category">
  2. <option value="" selected="selected">---------</option>
  3. {% for item in categories %}
  4. {% ifequal item.parent_id 0 %}
  5. <optgroup label="{{ item.name }}">
  6. <option value="{{ item.id }}">{{ item.name }}</option>
  7. {% for subitem in categories %}
  8. {% ifequal subitem.parent_id item.id %}
  9. <option value="{{ subitem.id }}">{{ subitem.name }}</option>
  10. {% endifequal %}
  11. {% endfor %}
  12. {% endifequal %}
  13. {% endfor %}

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.