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

In Django, when a UrlField is made read only, it prevents it from rendering as a clickable link. Why?

In Django (we are currently using 1.9), when we add an UrlField to a model, the Admin site correctly renders the UrlField value as a clickable link on edit views. If we were to mark this UrlField as readonly (through the ModelAdmin  readonly_fields…
Ad N
  • 7,930
  • 6
  • 36
  • 80
3
votes
1 answer

How to setup the initial value in select control?

I'm trying to setting up a select control on a form, but not achieving the expected results. For me, the strangest thing is it working in the previous control, same type. This is the function involved: class ProofMSPE(CrearEvidencia): model =…
toledano
  • 289
  • 11
  • 20
3
votes
3 answers

How to get a single widget to set 2 fields in Django?

I got a model with 2 fields: latitude and longitude. Right now they're 2 CharFields, but I want to make a custom widget to set it in admin - was thinking about displaying Google Maps, then getting the coordinates of the marker. But can I have 1…
kender
  • 85,663
  • 26
  • 103
  • 145
3
votes
2 answers

Render only one part of a MultiWidget in Django

I have a Django Form Field with a MultiWidget that consists of two TextInputs. When rendering the form in a template there is the handy notation {{ formname.fieldname }} for rendering a single field. When I use it for the field with the…
Philipp Zedler
  • 1,660
  • 1
  • 17
  • 36
3
votes
3 answers

Date format for django's SelectDateWidget

SelectDateWidget is very convenient but it normally seems to return dates in the format "%Y-%m-%d". It doesn't take a format parameter and doesn't have much documentation. Anyone run into this or have an idea how to work around it to get the output…
Purrell
  • 12,461
  • 16
  • 58
  • 70
3
votes
2 answers

In Django Admin, I want to change how foreign keys are displayed in a Many-Many Relationship admin widget

I have a ManyToMany relationship: class Book: title = models.CharField(...) isbn = models.CharField(...) def unicode(self): return self.title def ISBN(self): return self.isbn class Author: name = models.CharField(...) books =…
MikeN
  • 45,039
  • 49
  • 151
  • 227
3
votes
2 answers

How do I access the id of a Django Widget from the widget definition?

I am creating a custom widget for a datetime field: class MySplitDateTimeWidget(forms.SplitDateTimeWidget): def format_output(self, rendered_widgets): mytimeid = self.widgets[1].attrs['id'] #####NEED HELP HERE temp =…
rsp
  • 811
  • 2
  • 12
  • 32
3
votes
1 answer

How to work with time picker widget in Django template?

I am working on a Django based Application, and i stuck in some place where i want to save a time given by the user and the no of days (Monday-Sunday) in my database. user will choose a time from Time picker widget or any other way, but it return…
Amit Pal
  • 10,604
  • 26
  • 80
  • 160
3
votes
1 answer

Django form wont submit because of autocomplete widget field

I want to fill a text input in my form using an autocomplete widget that I have created using jquery ui. Everything works exactly how I want to, except when the form is submitted. The problem is that when I submit the form, the text input is…
danielrvt
  • 10,177
  • 20
  • 80
  • 121
2
votes
0 answers

TypeError - expected string or buffer for date field in django when using SelectDateWidget

I have a date field in my model, and I am using SelectDateWidget() to provide the user date selection option. The name of the field is deadline and here is how I set the widget in the model form widgets = { 'deadline' : SelectDateWidget(), …
Sachin
  • 3,672
  • 9
  • 55
  • 96
2
votes
1 answer

How assigned TypedChoiceField as form class to model Field with choices?

I had CharField with choices in the model, but I need for this field render as CheckboxSelectMultiple, which returns list to a form class. With TypedChoiceField form class, which automatic assigned to Field with choices, it's not validate. I decided…
I159
  • 29,741
  • 31
  • 97
  • 132
2
votes
1 answer

How to 'check' a value in a radio button by default in Django?

I wrote a model form. I used widgets to make radio buttons and I want a particular radio button to be checked by default while rendering the form in my html file. Model: class Room(models.Model): class Meta: number = …
2
votes
1 answer

Django Select 2 Widget not working , Field rendered but styles not applied

I have been trying to use multiple select using django-select2 widget for a while Step-1: I installed django-select2 using pip install django-select2 Step-2: Added it the installed app INSTALLED_APPS = [ ... django_select2 ... ] Step-3: I added the…
Sanjay Kapilesh
  • 269
  • 1
  • 4
  • 16
2
votes
3 answers

Preview Of Gallery in Django Admin

I want to display the selected gallery in my admin. I'm not very capable of writing custom fields and couldn't find any well documented guidelines about it. As for my question, I've written basic classes such as: class…
iva123
  • 3,395
  • 10
  • 47
  • 68
2
votes
1 answer

Changing the default markup of the RadioSelect django widget

I am using python version 3.6.8 and django version 3.0.8. I have seen a lot of topics related to this in this forum but some are very old answers. Not sure which one to follow. I tried referring to the django official documentation which exactly…
Pradeep
  • 619
  • 2
  • 10
  • 22