{% load trans from i18n %} {% comment %} File field seems to use a bound widget type that has an array of subwidgets but only has a single actual widget. The Bootstrap crispy theme just iterates over these widgets to get the first/only one. This might be a file field or image field, so there is conditional logic for display here. The Bootstrap theme used the instance data ``widget.data`` so this is following this pattern. Here's the data when the organization avatar field is rendered: { 'name': 'avatar', 'is_hidden': False, 'required': False, 'value': , 'attrs': { 'accept': 'image/*', 'id': 'id_avatar', 'aria-describedby': 'id_avatar_helptext', 'disabled': False, 'checked': False }, 'template_name': 'django/forms/widgets/clearable_file_input.html', 'type': 'file', 'checkbox_name': 'avatar-clear', 'checkbox_id': 'avatar-clear_id', 'is_initial': True, 'input_text': 'Change', 'initial_text': 'Currently', 'clear_checkbox_label': 'Clear' } {% endcomment %} {% for widget in field.subwidgets %} {# Confusingly named, but ``is_initial`` signals that there is a current value/file for the file field #} {% if widget.data.is_initial %}
{# Is the field for image MIME types? Show the image if so, otherwise basic file info. #} {% if widget.data.attrs.accept == "image/*" %}
{{ field.label }} {{ field.value.width }}x{{ field.value.height }}px
{% else %} {% endif %}
{% endif %}
{% endfor %}