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

Can I change a form widget class without redefining it explicitly in Django?

I'm trying to change the class of a Django form field. My form looks like: class MyForm(forms.Form): my_field = forms.ChoiceField(choices=myChoices) Why is it that it only works to change the class of the Select field explicitly? I want the…
YPCrumble
  • 26,610
  • 23
  • 107
  • 172
1
vote
1 answer

Django Iterating Over CheckboxSelectMultiple Renders Numbers

I'm trying to iterate over a MultipleSelect form that utilizes a CheckboxSelectMultiple widget and display each checkbox within. Here is the code for the iteration: {% for choice in form.mp4_rasters %}
coltonoscopy
  • 321
  • 4
  • 16
1
vote
1 answer

How to use django admin many to many field selector widget

I want to use this How can I use it for my many to many modelform. Basically I want the add button, which allows me to add the many to many objects.
Akash Deshpande
  • 2,583
  • 10
  • 41
  • 82
1
vote
2 answers

Django FilteredSelectMultiple with a massive amount of data

I have the following models: class Student(models.Model): class Meta: app_label = 'ground' name = models.CharField(max_length=255) def __unicode__(self): return unicode(self.name) class Program(models.Model): …
nelsonvarela
  • 2,310
  • 7
  • 27
  • 43
1
vote
1 answer

Cant get Custom widget to work by replacing django's default date time widget in django admin

I had asked a question here but I think its dead. I even updated it with my progress. So after that I worked a little more with firebug for firefox and discovered some errors that make no sense to me. But before that heres my code: (My app name is…
Indradhanush Gupta
  • 4,067
  • 10
  • 44
  • 60
1
vote
0 answers

Custom django field in admin-form

I`m trying to create form field for Django admin backend In database it should be CharField field, contains "0" and "1" values with 24*7 length. In admin panels I want to see them as 7 fields with 24 checkboxes each. The code: model.py: from…
1
vote
0 answers

How do I use widgets to add an attribute to a form in Django?

I'm trying to get a placeholder to show up for a form field but I'm doing something wrong with my form fields. Any thoughts? I've got the following classes: class EditField(forms.CharField): def __init__(self, *args, **kwargs): …
jchung
  • 903
  • 1
  • 11
  • 23
1
vote
1 answer

Django - custom widget - why does Django think I don't have 'attrs'?

EDIT: Using Django 1.3 I've built a Custom Widget to educate myself but I can't get past a problem where when the page is fetched Django says that: 'FooTestWidget' object has no attribute 'attrs' I don't want to use the 'attrs' argument and I've…
glaucon
  • 8,112
  • 9
  • 41
  • 63
1
vote
1 answer

Accessing ModelChoiceField queryset from custom widget

I have a form that has a ModelChoiceField. I have created a custom widget for dealing with ModelChoiceFields, the widget extends forms.TextInput, so: class SelectWidget(forms.TextInput): def __init__(self, attrs): super(SelectWidget,…
PT114
  • 931
  • 3
  • 10
  • 18
1
vote
1 answer

How can I extend a django admin widget so it's still optional?

I've been scouring the internet for a couple days and couldn't find anything, so I'm hoping you guys can point me in the right direction. I'm trying to customize the django admin so that a button appears inline after a URL field. The button appears,…
leo
  • 339
  • 2
  • 13
1
vote
1 answer

how to delete the ---- generated by select choices

i have a question on how do i get rid of the ---- from the select drop down menu not to show the null(---) in the first row. I found from stackoverflow on RadioSelect and i manage to get rid of the --- but i am stuck in the select drop down…
noobes
  • 161
  • 2
  • 18
1
vote
1 answer

Django bootstrap button widget

Is there any way to create a widget that generates twitter bootstrap buttons? I am needing to put some buttons in the middle of the form. (or html that are not inputs) Tried as follows: class BootstrapButtonWidget(forms.Widget): def render(self,…
Matheus Lima
  • 261
  • 1
  • 5
  • 8
1
vote
1 answer

Django Form Field Problems with Cloudinary's CloudinaryImage Class

I've got a Django form that is displaying a ClearableFileInput for a CloudinaryImage (from Cloudinary). Things are working great, except when I display the form field, I get a mangled href in the anchor element: Currently:
Erik
  • 7,479
  • 8
  • 62
  • 99
1
vote
1 answer

Django Contrib Comments: How to override the comment's textarea widget?

Using django.contrib.comments, I've defined a custom comment app. I wanted to override the text area widget so that the textbox appears smaller. So what I created was this: #forms.py class CustomCommentForm(CommentForm): #...otherstuff... …
powlo
  • 2,538
  • 3
  • 28
  • 38
1
vote
1 answer

Django 1.4 Want to make birthdate field utilizing SelectDateWidget not required on my form

I am trying to create a form for the user to change their profile account information on their own. Currently I have it so they can update their first, last and username, gender and 'birthdate'. The 'birthdate' is the only one I can't get to be not…