Django check if form choice is empty -
in template how possible check if modelchoicefield empty?
this form:
class batchform(forms.modelform): def __init__(self, user=none, *args, **kwargs): super(batchform, self).__init__(*args, **kwargs) this_templates = template.objects.for_user(user) self.fields["templates"] = forms.modelchoicefield(queryset=this_templates, required=false, empty_label=none)
then in views want not show drop down if queryset empty this...
{% if not form.templates%} <div class="control-group"> <div class="controls"> {{ form.templates }} </div> etc
you can do:
{% if form.templates.field.choices.queryset.all|length %} <div class="control-group"> <div class="controls"> {{ form.templates }} </div>
Comments
Post a Comment