I have form with MultipleChoiceField
field which has dynamic list for choices
. With the help of this form users can select data and add them to database.
Sometimes dynamic list can be empty []
. So I want to show message in template when its empty but next code didnt show me message. I use django-widget_tweaks
application in my template. Where is my mistake?
forms.py:
class RequirementForm(forms.ModelForm):
symbol = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple)
class Meta:
model = Requirement
fields = ('symbol',)
requirement_add.html:
{% load widget_tweaks %}
<form method="post" action="{% url 'project:requirement_add' project_code=project.code %}">
{% for field in form %}
{% render_field field class="form-control" %}
{% empty %}
<p>Form is empty!</p>
{% endfor %}
</form>