Questions tagged [django-widget]

Django widgets handle the rendering of the HTML for form fields

A widget is Django’s representation of a HTML input element. The widget handles the rendering of the HTML, and the extraction of data from a GET/POST dictionary that corresponds to the widget. -- https://docs.djangoproject.com/en/dev/ref/forms/widgets/

Django includes a number of built in widgets, including TextInput, RadioSelect and CheckboxInput. It is easy to change the way a form field is displayed by declaring the widget when you define your Django form.

For example, if you have a form ChoiceField, where the user can choose from a list of options, your choice of widget determines whether this is rendered as a dropdown menu, or a list of radio buttons.

If custom behavior is required, Django's built in widgets can be subclassed and extended.

329 questions
4
votes
1 answer

How do you modify the default widget for all builtin form fields of a certain type in Django?

This is a follow-up on How do you change the default widget for all Django date fields in a ModelForm?. Suppose you have a very large number of models (e.g. A-ZZZ) that is growing with the input of other developers that are beyond your control, and…
Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
4
votes
1 answer

Grouping CheckboxSelectMultiple Options in Django

In my Django App I have the following model: class SuperCategory(models.Model): name = models.CharField(max_length=100,) slug = models.SlugField(unique=True,) class Category(models.Model): name = models.CharField(max_length=100,) …
rrb_bbr
  • 2,966
  • 4
  • 24
  • 26
4
votes
4 answers

django radioselect render to table

I want to render the django form widget radioselect into a table rather than a ul list. With labels in the first row and the radio buttons below in the second row. One cell for each button. e.g. ------------------------------- | label 1 | label 2…
John
  • 21,047
  • 43
  • 114
  • 155
4
votes
0 answers

Django doesn't respect the maxlength widget attribute

I have the following field in model: short_description = models.CharField(max_length=205) and the widget in ModelForm: 'short_description': forms.Textarea(attrs={'rows': '3', 'minlength': 250,'maxlength': 250}) The issue: In HTML, input, Django…
user3541631
  • 3,686
  • 8
  • 48
  • 115
4
votes
4 answers

How to set width and input limit of NumberInput widget for IntegerField in a Django form

I'm looking for a way to change the width of the input box in a Django form. The model code for a parameter looks like this: my_integer = models.IntegerField('Window', default=50) And, putting it into a form, the HTML code that is generated is…
4
votes
0 answers

Django cms creation wizard form

I have an Article model with CharFields,models.DateTimeField and FilerFileField. I create form like this: class ArticleWizardForm(forms.ModelForm): class Meta: model = Article exclude = [] class Media: js =…
viliam
  • 141
  • 14
4
votes
2 answers

Caught DoesNotExist while rendering: Photo matching query does not exist

When I do the following inside an admin file: photo = Photo.objects.get(original_image__exact=file_name) val = photo.admin_thumbnail.url I get this error: Caught DoesNotExist while rendering: Photo matching query does not exist. Here is my…
demux
  • 4,544
  • 2
  • 32
  • 56
4
votes
1 answer

Django Custom Widget For ManyToMany field

Does anyone know of a widget that displays 2 select boxes. One shows a list of all object in a model and the other shows the objects which have been selected. The user can then select an object from the first list, click an >> button which moves…
John
  • 21,047
  • 43
  • 114
  • 155
4
votes
3 answers

django apply widget for all fields

Is there a way to apply css class to ALL fields instead of doing the following for every single field. forms.py class UserColorsForm(forms.ModelForm): class Meta: model = UserColors exclude = ('userid',) widgets = { …
deathangel908
  • 8,601
  • 8
  • 47
  • 81
4
votes
1 answer

Adding extra data to widget output for Foreignkey fields

Say I have the following models... class Person(models.Model): name = models.CharField() specialty = models.CharField() class Team(models.Model): captain = models.ForeignKey(Person) vice_captain = models.ForeignKey(Person) and I have…
neRok
  • 995
  • 9
  • 21
4
votes
2 answers

Cannot overwrite step attribute of NumberInput field in django

I'm trying to make a NumberInput widget that has steps of 0.5, which is defined in the form as the following: widgets = { "hours_per_day": widgets.NumberInput(attrs={'step': '0.5'}) } However, the template is always rendered with the attribute…
Seth Rubin
  • 43
  • 1
  • 4
4
votes
1 answer

Django: change admin FileField output?

I've made a model with file that is uploaded to custom path (not in MEDIA_ROOT). So it's some kind like protected file. Now I need to change it's representation in admin details. It shows a path relative to MEDIA_URL. I need to change that, to show…
tunarob
  • 2,768
  • 4
  • 31
  • 48
4
votes
1 answer

Custom widget not validating only the first time

I've created a custom widget OrderedCheckboxSelectMultiple, I'm just replacing
    for
      and adding some classes to
César
  • 9,939
  • 6
  • 53
  • 74
4
votes
0 answers

How to access MultiValueField's SubFields in template

I am trying to get a nice presentatin of a DatTime picker following this approach. So I have a subclass of MultiValueField with two SubFields and a widget which is a subclass of MultiWidget and which passes the correct css classes to its subwidgets…
black_puppydog
  • 950
  • 13
  • 21
3
votes
2 answers

Customize Django Admin Change Form Foreignkey to Include View Record

When selecting a foreignkey in the django admin change form I am trying to add an href that can view the record next to the plus that adds the record. What I've tried just to get the href to render is I've copied out the admins def render into my…
Crazyconoli
  • 641
  • 1
  • 6
  • 18