Update form rendering

This commit is contained in:
Gabriel Augendre 2020-08-20 09:48:11 +02:00
parent b96843a231
commit 80348c4e03

View file

@ -10,3 +10,24 @@ class CommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = ["username", "email", "content"]
def as_table(self):
"Return this form rendered as HTML <tr>s -- excluding the <table></table>."
return self._html_output(
normal_row="<tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>",
error_row=(
'<tr class="error nonfield"><td colspan="2">%s</td></tr>'
'<tr class="spacer"><td colspan="2"></td></tr>'
),
row_ender="</td></tr>",
help_text_html='<br><span class="helptext">%s</span>',
errors_on_separate_row=False,
)
def __init__(self, *args, **kwargs):
defaults = {
"label_suffix": "",
}
defaults.update(kwargs)
super().__init__(*args, **defaults)