D
D
DavLivesey2020-07-29 14:41:00
Django
DavLivesey, 2020-07-29 14:41:00

How to form a label in Django in the META class of a form?

I can't figure out why the label dictionary is not being passed to the request form. That is, in the form, the fields are simply called text and group.

The form:

class PostForm(forms.ModelForm):   
    text = forms.CharField(widget= forms.Textarea)
    group = forms.ModelChoiceField(queryset=Group.objects.all(), required=False)
    class Meta():
        model = Post
        fields = ['text', 'group']
        label = {'text':'Введите текст', 'group':'Выберите группу'}
        help_text = {'text':'Любую абракадабру', 'group':'Из уже существующих'}


html:
{% for field in form %}
                        <div class="form-group row" aria-required={% if field.field.required %}"true"{% else %}"false"{% endif %}>
                                <label for="{{ field.id_for_label }}" class="col-md-4 col-form-label text-md-right">{{ field.label }}{% if field.field.required %}<span class="required">*</span>{% endif %}</label>
                                <div class="col-md-6">
                                    {{ field|addclass:"form-control" }}
                                    {% if field.help_text %}
                                    <small id="{{ field.id_for_label }}-help" class="form-text text-muted">{{ field.help_text|safe }}</small>
                                    {% endif %}
                                </div>
                        </div>
                    {% endfor %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-07-29
@bacon

labels vs. labels

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question