[Answered ]-Custom django form fields

2👍

Your code is very similar to this Django snippet. A comment there suggests using:

    <label for="{{ field.auto_id }}">

instead of your:

    <label for="id_{{ field.label }}">

You can also try this snippet as an alternative.

0👍

template:

<label for="{{ user_form.first_name.id_for_label }}" class="{{ user_form.first_name.css_classes }}">{{ user_form.first_name.label }}{{ user_form.label_suffix }}</label>

forms.py:

class UserChangeForm(DjangoUserChangeForm):
    error_css_class = 'field_error'
    required_css_class = 'field_required'

CSS:

.field_required:after {
    content: " *";
}
👤Googol

Leave a comment