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
1
vote
1 answer

Multi field and computed value

I need a solution for this problem: I would like to have MultiField widget for a "value" field. This field should allow to input two values (two input widgets), and user should choose which of these values is to be saved (two checkbox widgets).…
1
vote
0 answers

AutocompleteSelect broken after moving from django 2.2 to django 3.2

Hello :) After upgrading Django version to 3.2, widget AutocompleteSelect that I use in django admin panel (to have a drop-down from which I can choose an object) is broken. The error I see is AttributeError at /admin/question/ 'QuerySet' object has…
exo
  • 41
  • 1
  • 6
1
vote
2 answers

Django DateInput widget format

I am trying to change the date format from mm/dd/yyyy to dd/mm/yyyy in a DateInput widget. I am trying to change the format the following way. class Meta: model = Patient fields = '__all__' widgets = { 'date_of_birth':…
1
vote
3 answers

django duplicate widget requirements

If we have multiple files defining widget classes, and if widgets have e.g class W1(forms.DateInput): class Media: css = {'all':('common/css/ui-darkness/jquery-ui-1.8.9.custom.css',),} js =…
goh
  • 27,631
  • 28
  • 89
  • 151
1
vote
1 answer

Django Admin FilteredSelectMultiple Widget selection doesn't work

I am trying to use the FilteredSelectMultiple widget from the admin widgets library. I was able to get the widget displayed on the web page. However, I cannot get the buttons to move the selections to the Chosen box. Here is my code: forms.py from…
don
  • 597
  • 2
  • 8
  • 28
1
vote
1 answer

Django Model Forms including Foreign Key Fields

I am trying to create a Model Form in Django that includes Foreign Key fields from the Athlete Table. Normally when referring to the Foreign Key fields I can use the field name 'athlete' then.followed by the field name. This does not seem to be…
Mark
  • 135
  • 1
  • 12
1
vote
1 answer

Django AuthenticationForm Customization

I am relatively new to django and want to customize the AuthenticationForm but an not sure how to do it. I essentially want to override the init function to be able to inject attributes and control what is displayed on the form. Specifically I would…
mharre
  • 233
  • 3
  • 17
1
vote
1 answer

Why widget EmailInput style doesn't apply

I'm trying to style the django forms, I could apply the class to the TextInputs with widget but for the email and password it doesn't apply. Any idea why? Also, how can I delete the text above password? The password requisites, it isn't…
Risker
  • 358
  • 3
  • 15
1
vote
0 answers

how do I change the date format on selectDate django widget?

I have a date field of a form and I want it to have a format like '21 jan 2020' but I can't find a way to pass it on the selectDate widget class MemoryForm(ModelForm): class Meta: model = Memory fields = ["date"] labels…
1
vote
3 answers

relationship choices¶widget showing text

I would like to display choices of Test_Baustoff->art Model in my Test_Objekt Model Form. Right now i am trying to solve it with a Widget... Models: class Test_Objekt(models.Model): baustoffid = models.ForeignKey(Test_Baustoff,…
1
vote
0 answers

Django forms foreign key field read only gives value error during Update form

models.py class MyModel(models.Model): company = models.ForeignKey(Company, db_column="company", default=None, on_delete=models.DO_NOTHING, null=True) forms.py class myform(forms.ModelForm): company = forms.CharField(label="company", …
1
vote
1 answer

Many to many fields in widget form

I have problem with display many to many field in form widget. Category is not display in template. Title is ok (is display) but category isn't - category is empty. What can I do to display many to many fields in my template form with multiplechoice…
AM0k
  • 90
  • 5
1
vote
1 answer

check that the dates are entered correctly in a form

I have a form to create events and I want to check that the dates are correct: end date greater than the start date or dates not before the actual date, etc... I was checking on the internet if there was any check with django for…
1
vote
0 answers

How to customize Django TimeField()?

There is a restaurant table reservation app which I am trying to make that has DateField() and TimeField() fields. Now suppose there is a table booking for XX:xx time and XX/XX/XXXX date. Now in the rendered HTML form, I want the reserved time to…
1
vote
0 answers

Is there a specific way to reference templates for widgets in django?

I created my own widget which inherited from the Widget class which functions much like a Select widget. Only it was causing the page to take ages to load. Thus started a debugging session which has resulted in the following discovery. When my…
user1849962
  • 1,273
  • 1
  • 11
  • 16