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
2
votes
1 answer

Django CheckboxSelectMultiple not displaying in ModelForm

I'm trying to use CheckboxSelectMultiple in a form, instead of the SelectMultiple default. I tried two different ways to make it display as checkboxes, but they both display the default SelectMultiple on my local webpage. Everything else renders…
Crowl
  • 37
  • 5
2
votes
0 answers

Django Model Field as Button Group

How can i create a button group using Django model fields and widgets? #models.py GENDER_CHOICES = ( ('M', 'Male'), ('F', 'Female'), ('-', 'Other') ) class Profile(models.Model): gender = models.CharField(choices=GENDER_CHOICES,…
2
votes
0 answers

Styling django MultiSelectField

I want to create multipleselecetfild that each selection referin to each choice appears below the image. I used the django MultiSelectField to create a form to have multiple select options. These are my files: models.py class…
2
votes
2 answers

How to use TimeInput widget in Django forms?

TimeInput is not working for the form given below. But SelectDateWidget() works fine. No error is created for current TimeInput() widget. Suggest the correct way to use TimeInput widget. forms.py class TournmentDetails(forms.ModelForm): class…
VA splash
  • 553
  • 1
  • 8
  • 25
2
votes
0 answers

widget css Attribute not updating Authentication form django 2.1

Sorry for stupid question as i am new to programming. (Start out as a hobby and now starting a project to replace work-related task rather than using excel) trying to customize user model and extending django user models and authenication form but…
2
votes
2 answers

Django SelectDateWidget not rendering correctly

I am trying to render the built-in SelectDateWidget in Django, however in the webpage it shows as Submit I am new to Django, I read the documentation and looked up on the internet, but…
C. Keylan
  • 58
  • 4
2
votes
1 answer

Django Custom widget rendering

The General Problem Suppose you have a certain model class MyModel(models.Model): Name = models.CharField(max_length=64) And an accompaniying form you use for creation class CreateMyModelForm(forms.ModelForm): class Meta: model =…
robotHamster
  • 609
  • 1
  • 7
  • 24
2
votes
0 answers

Default specific option checked in ParentalManyToManyField wagtail, using django-form

I am working with a multi-site wagtail project. And I want an event class which contains ParentalManyToManyField field called sites. The idea is that each event will be associated with multiple sites not necessarily all. Two sites X and Y have lots…
Bikash kharel
  • 472
  • 7
  • 16
2
votes
1 answer

Replacement for django `render_options`

So I am implementing this answer: Country/State/City dropdown menus inside the Django admin inline, but the def render piece of code needs to be redone.... I have managed to redo it, but I am struggling to find a replacement (or the correct code)…
Walucas
  • 2,549
  • 1
  • 21
  • 44
2
votes
2 answers

How to change the width of a drop-down field in a django form using widget attributes not css

I am trying to make all of the fields in my Django form have the same size to look tidy. I have text input, drop down and text area. I am creating the form using the Ticket model so I am not defining the form fields explicitly. I was able to resize…
Ibo
  • 4,081
  • 6
  • 45
  • 65
2
votes
2 answers

How to change size of CharField

This code is changing sizes of all CharFields in class. How I can change size of one CharField? formfield_overrides = { models.CharField: {'widget': TextInput(attrs={'size': '20'})}, }
SBrain
  • 333
  • 3
  • 12
2
votes
2 answers

How do I remove from Django widgets HTML5 attributes

Django Widgets set HTML5 maxlength attribute, based on the Model max_length. class Publication(models.Model): name = models.CharField(max_length=255) I want to remove this attribute,…
user3541631
  • 3,686
  • 8
  • 48
  • 115
2
votes
2 answers

Override in the widget attributes the max_length set on the Model

In the Model I set the maxlength of the field: short_description = models.CharField(max_length=405) In the ModelForm in the widget attributes I set minlength an maxlength: class ItemModelForm(forms.ModelForm): class Meta: model = Item …
user3541631
  • 3,686
  • 8
  • 48
  • 115
2
votes
1 answer

django admin 1.11 add an attribute to the options of a select

In django 1.11 admin, I have a list field and I would add an attribute in each
kosner
  • 77
  • 11
2
votes
3 answers

How to change datetime format in Django-filter form?

I'm creating a filter which contains datetime range choice. I would like user to be able to input date in this format: 24.08.2017 17:09 From docs, it is possible to specify a widget (from django.forms) and widget has attribute input_formats. So…
Milano
  • 18,048
  • 37
  • 153
  • 353