{% if widget %}
    {# Django 1.11+ #}
    {% for group, options, index in widget.optgroups %}
      {% for option in options %}
        {% include option.template_name with widget=option %}{% endfor %}
    {% endfor %}
{% elif selects %}
    {# Django < 1.11 #}
    {% for item in selects %}
        {{ item }}
    {% endfor %}
{% endif %}