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

django one widget for two m2m fields

I have two manytomany fields for my model ModelFrom, that both go to the same Model, call it ModelTo. ModelFrom(models.Model): field_one = ManyToManyField(ModelTo) checked = ManyToManyField(ModelTo) checked is a subset of field one. I have…
straykiwi
  • 538
  • 6
  • 23
1
vote
1 answer

Error saving records from ModelChoice Field in django form

I have a FormModel with an modelchoice field. The modelchoice widget is filtered based on the logged user class ProcFTPForm(forms.ModelForm): #id_archivo =…
joselegit
  • 533
  • 1
  • 14
  • 35
1
vote
1 answer

Django Forms - change the render multiple select widget

In my model I have a manytomany field mentors = models.ManyToManyField(MentorArea, verbose_name='Areas', blank=True) In my form I want to render this as: drop down box with list of all MentorArea objects which has not been associated with the…
John
  • 21,047
  • 43
  • 114
  • 155
1
vote
1 answer

Django , Changing color of Boolean widget in list display

I have a Django Boolean Field which is shown with pretty 'on' 'off' buttons in the list display (green and red). Is it possible to have a third state like yellow or blue, indicating state is unknown. PS : I have read about NullBooleanField, but that…
Wizard
  • 21
  • 2
1
vote
1 answer

Django ImageField widget to add thumbnail with clearable checkbox

I have a model like this class Participation(models.Model): # ... some attributes ... thumbnail = models.ImageField( verbose_name='immagine di copertina', blank=True, null=True, ) and I add the following code to…
1
vote
1 answer

conditionally change widget type in django form

I have the following simple form: class ContactEmailForm(forms.ModelForm): subject = forms.ChoiceField(choices=SUBJECT_TYPES) class Meta: model = ContactEmail fields = ('name', 'email', 'subject', 'message',) I want to…
Atma
  • 29,141
  • 56
  • 198
  • 299
1
vote
3 answers

Django: How to add dynamic classes to select options in a form

I have a ModelForm that I'm rendering in the template with django-widget-tweaks. I have a ChoiceField select that prints out something like this: But for Javascript manipulation…
grokpot
  • 1,462
  • 20
  • 26
1
vote
2 answers

__init__() got an unexpected keyword argument 'widget'

I'm trying to run web app page which uses the below form; class InputParametersForm(ModelForm): sqlConnection = SQLSeverConnection( 'MSSQLServerDataSource', 'default_user', 'password123!!', 'HD' ) …
Mark Corrigan
  • 544
  • 2
  • 11
  • 29
1
vote
4 answers

Django- How to determine field types in ModelForm init?

I want to change widget for all BooleanField's in model to Yes/No radio buttons, thought it will be simple: def __init__(self, *args, **kwargs): logger.debug("%s -------" % self.__class__.__name__) …
Lord_JABA
  • 2,545
  • 7
  • 31
  • 58
1
vote
0 answers

Django & jQuery - How to use the TagSelectMultiple widget

I am trying to use the jquery-tagselector widget from stackoverflow's user Julio César with Django, and I am quite lost... My form is: class CreationForm(forms.Form): tags =…
Erwan
  • 1,055
  • 1
  • 12
  • 26
1
vote
0 answers

Is it possible to use multiselect widget feature for a one-to-many model in Django?

I am working on implementing features on Django Admin site, and I want to create a multiselect dropdown menu for a one-to-many model. For example, like this: Django multi-select widget? But it looks like I can only use it for many-to-many models.…
user2857014
  • 507
  • 3
  • 10
  • 22
1
vote
1 answer

Overwrite clean method in Django Custom Forms

I have wrote a custom widget class AutoCompleteWidget(widgets.TextInput): """ widget to show an autocomplete box which returns a list on nodes available to be tagged """ def render(self, name, value, attrs=None): final_attrs =…
John
  • 21,047
  • 43
  • 114
  • 155
1
vote
1 answer

Django disable widget caching?

So I have a form where I defined a select widget like this: class AdHocVoucherTemplateForm(ModelForm): class Meta: model = AdHocVoucherTemplate widgets = { 'retailer_id': Select(choices=[(r.pk, r.name) for r in…
Richard Knop
  • 81,041
  • 149
  • 392
  • 552
1
vote
1 answer

In django forms custom widget return list as value instead of string

I am writting a custom widget which I want to return a list as the value. From what I can find to set the value that is returned you create a custom value_from_datadict function. I have done this def value_from_datadict(self, data, files, name): …
John
  • 21,047
  • 43
  • 114
  • 155
1
vote
1 answer

django quantity form widget

I want to develop a basic quantity widget that is a dropdown selection box, consuming an integer which will be the maximum amount of quantity, users can select from 1 to the maximum quantity. And in the end my form will be using this widget and if…
Hellnar
  • 62,315
  • 79
  • 204
  • 279