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

In Django custom MultiWidget how can get sub-widgets ids

In Django how to can get ids of sub-widgets that added to custom MultiWidget, for example if I want to attach a JavaScript code to rendered widgets how can I do it?
M.javid
  • 6,387
  • 3
  • 41
  • 56
0
votes
1 answer

Django custom widget, populate from another table (similar to inlines)

I am writing a custom widget for multiple image uploads. My models are: models.py class Room(models.Model): .... .... class Picture (models.Model): room = models.ForeignKey(Room) url=models.ImageField(upload_to='slider',…
Nebojsha
  • 381
  • 2
  • 10
0
votes
1 answer

MultiWidget in MultiWidget how to compress the first one?

I have two MultiWidget one inside the other, but the problem is that the MultiWidget contained don't return compress, how do i do to get the right value from the first widget? In this case from SplitTimeWidget class…
sacabuche
  • 2,781
  • 1
  • 27
  • 35
0
votes
1 answer

Exception Type: ValueError Exception Value:too many values to unpack - Django

I'm getting this error when I'm rendering the below from as (form.as_ul) class InputParametersForm(ModelForm): sqlConnection = SQLSeverConnection('MSSQLServerDataSource') tableChoices = {'id': 'value'} sqlQuery = sqlConnection.getTableNames() for…
0
votes
1 answer

How to set modelformset widget.label with value of other model field?

I have a modelformset for a PersonTag model with 3 fields, and I want to display a checkbox widget for the PersonTag.enabled field, and no widget for the other two fields. For each checkbox, I want the label to be set to the PersonTag.tag value for…
Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
0
votes
0 answers

django frontend inline form for ManyToMany displayed as table with add option

I need a way to add (and edit) elements (connected with M2M) in a frontend (not admin) form. My Models: class IngredientName(models.Model): name = models.CharField(_('name of ingredient'), max_length=255) class Unit(models.Model): …
welworx
  • 370
  • 2
  • 14
0
votes
1 answer

Django - Remove the Checkbox in ClearableFileInput widget

I'm finding it overly difficult to customize ClearableFileInput as set as the default widget in a modelForm that includes an ImageField in the model. Particularly I don't want the Delete Checkbox that is part of the widget. I've tried…
jayuu
  • 443
  • 1
  • 4
  • 17
0
votes
1 answer

Django Selectmultiple

First of all, excuse for my english ^^ I don't understand how i can use the select multiple widget in django. I mean, i don't understang which files and functions are necessary. Example, I have two classes : class Student(models.Model): …
Raphael
  • 546
  • 2
  • 6
  • 25
0
votes
1 answer

Django: CSS class does not show for ModelForm that extends another ModelForm

I need to assign a CSS class to a form field and I was referring to this SO post: CSS styling in Django forms However, I could not get it to work with ModelForm that extends another ModelForm. In the code below the fields "title" and "base_title"…
jazzblue
  • 2,411
  • 4
  • 38
  • 63
0
votes
1 answer

django custom date_field widget by datepicker

So, I want to use a JS library called datepicker as a template for my date fields in forms. My custom widget`s code just renders a template: class MyDateWidget(SelectDateWidget): def render(self, name, value, attrs=None): template =…
0
votes
1 answer

trouble with inline and jquery plugins in django

Have troubles with inline in django admin. For example, i want to add a chosen jquery plugin to my Change_form page. I'm extends change_from html and add next code {% extends "admin/change_form.html" %} {% block extrahead %} {{ block.super…
Arti
  • 7,356
  • 12
  • 57
  • 122
0
votes
1 answer

Customizing Select in Django

I have the following model class Color(models.Model): """ Colors """ name = models.CharField(max_length=50, db_column="name", unique=True) hex = models.CharField(max_length=6, db_column="hex", unique=True) This model is…
Paul R
  • 2,631
  • 3
  • 38
  • 72
0
votes
2 answers

Django admin - dynamically update through ajax choices of a ChoiceField in ModelForm

I'm working with a ModelForm in the admin. I have two ChoiceFields which are populated with choices in __init__: self.fields['city'] = forms.ChoiceField( required=False, …
Luke
  • 1,794
  • 10
  • 43
  • 70
0
votes
1 answer

Analogue of the WordPress "is_admin" function for Django? (For check location, not permissions.)

I need something like that function for Django. Reason: I write widget with separate config for admin and other pages. Config determined in custom field: class Article(models.Model): field = CustomField(config={'default': {}, 'admin': {}}) For…
lampslave
  • 1,431
  • 1
  • 15
  • 20
0
votes
1 answer

How do I add a blank default option to a select widget?

I'm attempting to create a search page for a database that I am maintaining by creating a dynamically maintained select box of all of the unique values of a few of my fields. After much time and thought, I've decided that the best way to create a…
seaturtlecook
  • 243
  • 1
  • 2
  • 5
1 2 3
21
22