A
A
Alexander Bondarenko2020-08-03 17:46:49
Django
Alexander Bondarenko, 2020-08-03 17:46:49

How can a class be added to a django form field?

from django import forms

PAYMENT_METHOD_CHOICE=(
   ('Наличные', 'Наличными курьеру'),
   ('Картой', 'Оплата картой на сайте')
)

PERSON_COUNT_CHOICE=[(i, str(i)) for i in range(1, 6)]

class SendForm(forms.Form):
    name = forms.CharField(max_length=25)
    number = forms.CharField(max_length=25)
    street = forms.CharField(max_length=200)
    house = forms.CharField(max_length=100)
    entrance = forms.IntegerField(required=False)
    corps = forms.IntegerField(required=False)
    floor=forms.IntegerField(required=False)
    payment_method = forms.ChoiceField(choices=PAYMENT_METHOD_CHOICE, widget=forms.RadioSelect())
    surrender = forms.DecimalField(required=False)
    person_count = forms.TypedChoiceField(choices=PERSON_COUNT_CHOICE, coerce=int)
    comments = forms.CharField(required=False,
                               widget=forms.Textarea)

How can I add a class to these fields? The output in the documentation does not show how to add a class, is there any solution?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alternativshik, 2020-08-04
@alternativshik

There are several solutions and everything is in the documentation

A
Alexander Bondarenko, 2020-08-07
@bond_1013

Here is a link to the implementation , maybe it will help someone

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question