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 %}
<label for="{{ field.auto_id }}">
{% if field.field.required %}<span class="required">{{ field.label }}</span>
{% else %}{{ field.label }}{% endif %}
{{ field }}
{{ field.errors }}
{% endfor %}

[ Source ]

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