{% load i18n %}
<div class="btn-group" role="group" aria-label="{{ widget.name }}">
  {% for val, label in widget.choices %}
    {% with forloop.counter0 as idx %}
      {% with id=widget.name|add:"_"|add:idx %}
      <input
        type="radio"
        class="btn-check"
        name="{{ widget.name }}"
        id="{{ widget.name }}_{{ idx }}"
        value="{{ val }}"
        {% if val|stringformat:"s" == widget.value|stringformat:"s" %}checked{% endif %}
        autocomplete="off"
      >
      <label
        class="btn btn-outline-primary {% if val|stringformat:"s" == widget.value|stringformat:"s" %}active{% endif %}"
        for="{{ widget.name }}_{{ idx }}"
      >
        {{ label }}
      </label>
      {% endwith %}
    {% endwith %}
  {% endfor %}
</div>
