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

django-crispy-forms bootstrap 4: How to display checkboxes horizontally?

I can't seem to make my CheckboxSelectMultiple widget to display horizontally using django-crispy-forms/bootstrap4. I've tried : Specifying it on the form's widgets : widgets = {'my_field': forms.CheckboxSelectMultiple(attrs={'class':…
0
votes
1 answer

Django Forms with Foreign Key using Materialize

What I Want Create the same form that shows on Django admin on templates. The Problem I cannot load the foreign keys into the forms. I was searching for a solution for two days. I have read the Django documentation for ModelForm and QuerySet but I…
Andre Nevares
  • 711
  • 6
  • 21
0
votes
1 answer

Adding modelForm validation constraints in Django for a Meta class

I need to add some validation constraints on my CustomUserCreationForm Meta class. I can't find where and how to add it. Should I use a RegexValidator or not for this purpose? For example I'd like the first_name to be minimum length 2 and maximum…
Welyweloo
  • 88
  • 8
0
votes
1 answer

Django DateInput widget format doesn't change

I hate a Datetime field and a widget to select a date. Currently it's in mm/dd/yyyy format. I need it to be in dd/mm/yyyy, nothing suggested in other answers seems to have a result: My settings.py DATE_FORMAT = '%d/%m/%Y' DATE_INPUT_FORMATS =…
Margo
  • 348
  • 2
  • 3
  • 13
0
votes
1 answer

How to create a a checkbox/radiobutton for every choice of an attrubute using django-filter

I have a model Property class Property(models.Model): PROPERTY_CATEGORIES = ( ('flat/apartment 1BHK','flat/apartment 1BHK'), ('flat/apartment 2BHK','flat/apartment 2BHK'), ('flat/apartment 3BHK','flat/apartment…
0
votes
1 answer

Dynamically Update MultipleChoiceField Option Attributes in Django Form

I'm utilizing Django Forms for my web application's front-end filter functionality, and I'm making a few Field customizations so that I may present multi-select checkboxes with custom labels as follows: [x] Doug Funny (1) [ ] Skeeter Valentine(5)…
littleK
  • 19,521
  • 30
  • 128
  • 188
0
votes
0 answers

How To Unit Test Blank DateTimeField

I am trying to unit test a form which includes a date selector. It is saved in the model as DateTimeField and in the form uses a DatePickerInput widget. This is the test: def test_form_validation_for_blank_items(self): user =…
horse
  • 479
  • 7
  • 25
0
votes
1 answer

ModelMultipleChoiceFilter - Field 'id' expected a number but got 'Diner'

So I have a simple Ad model and a FilterView showing all the ads. The ads can be filtered by different tags stored in a separate model joined by a ManyToManyField. I'm using django-filter to set up a small ModelMultipleChoiceFilter and let users…
Kevin D.
  • 315
  • 2
  • 19
0
votes
2 answers

TypeError: __init__() got an unexpected keyword argument 'attrs'

I know this question had been asked many times but I still cant figure it out yet. from django.contrib.auth.forms import UserCreationForm from django.forms import ModelForm from django import forms from . models import Profile from…
0
votes
1 answer

Django UpdateForm DateInput widget not showing date

I'm using the DateInput widget to provide a datepicker when a date field is input. However on my update form, the form pulls all the data for that recordd, except the date, which shows up as: dd/mm/yyy How do I get the already input date to…
iFunction
  • 1,208
  • 5
  • 21
  • 35
0
votes
1 answer

How to use widgets in Django Crisp Forms

I am using Django Crispy forms and its FormHelper. In my FormHelper class i want that one of the field should use widgets. The reason for using widget is that i want to populate a date picker in one of the field. Using the Field, i am able to…
0
votes
0 answers

Django ModelForm widget and non-widget field ordering

I have a django (1.11.9) ModelForm for events with times (start and end). When I display it to the user in a template I want last_field to be the last field in the form at the bottom: class EventForm(forms.ModelForm): dt = '%Y-%m-%d %H:%M' …
Chris B.
  • 1,505
  • 5
  • 26
  • 48
0
votes
1 answer

Django admin CheckboxSelectMultiple widget not working for ManyToManyField

I'm using the below model where the default django users table has a many-to-many relationship with Hotel's. Assigning multiple users to a Hotel in the django admin panel is difficult, and I want to replace the default 'ctrl-click' method to a…
0
votes
1 answer

Django model-forms widget choice based on URL variables

lets say I have a form based on the model: Form1: class Meta: model = Comment widgets = {"field1": forms.HiddenInput } # option 1 #or widgets = {"field2": forms.HiddenInput } # option 2 And I have 2 widgets options . First…
Aleksei Khatkevich
  • 1,923
  • 2
  • 10
  • 27
0
votes
2 answers

Overriding ModelForm with widgets

A user has a form where he can save sensitive data. I am capable of crypting this data and store it in the database using modelforms. However, if the user wants to modify this data, it appears in the TextInput from the form. I've read this post,…