[Django]-Access object in ModelChoiceField in Django

2👍

use something like this:

{% for field in form.visible_fields %}{# loop over form fields #}
    {% if field.name == "choice_field_name" %}
        {% for choice in field.queryset %} {# loop over choices #}
            {# here you access to choice object #}
        {% endfor %}
    {% endif %}
{% endfor %}

Leave a comment