django: Mark field as required on a form

A simple little feature which is lacking from the automatic form generation is marking something as required.

It's a bit of a shame that you have to override the whole form to get this working, but it gives more flexibility to how you want the required markings to be displayed.

{% for field in form %}
<div>
<label for="{{ field.auto_id }}">
{% if field.field.required %}<span class="required">{{ field.label }}</span>
{% else %}{{ field.label }}{% endif %}
</label>
{{ field }}
{{ field.errors }}
</div>
{% endfor %}

[ Source ]

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog