When using the Django admin forms to create a new or modify an existing object, the <label>
tags of mandatory model fields are declared with class attribute required
, e.g.
<div>
<label class="required" for="id_title">Title:</label>
<input class="vTextField" id="id_title" maxlength="255" name="title" type="text" required />
<p class="help">A title for this tool</p>
</div>
However, this is not the case when using Django ModelForm. The HTML code produced by the following piece of code in a template file
<table>
{{ toolForm.as_table }}
</table>
comes without any class attributes for the <label>
tag that would help to style appropriately labels of fields which are required:
<table>
<tr>
<th>
<label for="id_title">Title:</label>
</th>
<td>
<input id="id_title" maxlength="255" name="title" type="text" required />
<br /><span class="helptext">A title for this tool</span>
</td>
</tr>
</table>
Any ideas how to mark the label of mandatory fields in an efficient way?