Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Form field size

In Django Templates, how do i specify the size of a field

This is my form class:

class PstForm(forms.Form):
     hours = forms.ChoiceField(choices=[(6,6),(24,24),(48,48)], widget=forms.Select(attrs={'size':'3'}))

however this still renders a rather long field

how do i limit the size?

like image 393
Eva611 Avatar asked Jun 03 '11 21:06

Eva611


People also ask

What is CharField in Django?

CharField in Django Forms is a string field, for small- to large-sized strings. It is used for taking text inputs from the user. The default widget for this input is TextInput.

How do you exclude a specific field from a ModelForm?

Set the exclude attribute of the ModelForm 's inner Meta class to a list of fields to be excluded from the form.

What is Attrs Django?

attrs . A dictionary containing HTML attributes to be set on the rendered DateInput and TimeInput widgets, respectively. If these attributes aren't set, Widget. attrs is used instead.

How do I get form fields in Django?

Basically to extract data from a form field of a form, all you have to do is use the form. is_valid() function along with the form. cleaned_data. get() function, passing in the name of the form field into this function as a parameter.


1 Answers

You could try adjusting the CSS: attrs={'style': 'width:10px'}, (or 'class': 'some-class', etc).

like image 144
zeekay Avatar answered Oct 11 '22 01:10

zeekay