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
2
votes
0 answers

Tree with checkboxes | DJANGO

I have model Program with ManyToManyField function. I need too create form where as in the picture below where users can select and add functions to program. In other words I need TreeView with checkbox. How create such widget? I found django-mptt…
Nurzhan Nogerbek
  • 4,806
  • 16
  • 87
  • 193
2
votes
0 answers

Django CheckboxSelectMultiple() widget - Form widget value not selected after saving data options

How to can I work with multiple select options and make these options selected to stay selected ? Some application? Should I use any JS? Is possible that my approach may be incomplete or miss something ...? Context I have the following…
bgarcial
  • 2,915
  • 10
  • 56
  • 123
2
votes
1 answer

Is it possible to remove 'Currently' label when using django-stdimage?

I am using django-stdimage in my Django app and it works great, the only problem is that I want to remove the 'Currently' string, the clear checkbox and the rest of the decoration from the HTML template. I can't figure out how to achieve this. Here…
juankysmith
  • 11,839
  • 5
  • 37
  • 62
2
votes
4 answers

Django Error: TypeError: __init__() got an unexpected keyword argument 'attrs'

I'm trying to create a form where I'm getting certain details from the user. I have defined fields in forms.py and I'm also defining other attributes like placeholder and css class using django widget system. But it is showing me a…
Dhaval Simaria
  • 1,886
  • 3
  • 28
  • 36
2
votes
0 answers

Django m2m through model with classic admin widget

I need to customise a through model of a many-to-many relationship, the customisation is subtle, because the user won't need do act manually, I try to explain myself better by explaining my use case with the following pseudo…
nemesisdesign
  • 8,159
  • 12
  • 58
  • 97
2
votes
1 answer

django modelform css class for select

I am trying to add in a class with the name of autocomplete into one of my select. class MyForm(ModelForm): class Meta: model = MyModel exclude = ['user'] def __init__(self, user, *args, **kwargs): super(MyForm,…
ApPeL
  • 4,801
  • 9
  • 47
  • 84
2
votes
1 answer

Unable to override SelectMultiple widget in ModelForm (Django)

I have a ManyToManyField that I want to present in a form, as a CheckboxSelectMultiple widget. Why don't any of these methods work? (See Attempt #1, #2 and #3 below.) According to everything I've read in the docs and on SO, at least one of them…
pfctdayelise
  • 5,115
  • 3
  • 32
  • 52
2
votes
1 answer

Specify Widget's class

I have a custom form with a field using a custom widget. I need to set the class of the widget, and currently I can only do it like this: class DesignCampaignForm(ModelForm): brand_logo = FileField(widget=ImagePreviewWidget) …
blueFast
  • 41,341
  • 63
  • 198
  • 344
2
votes
1 answer

create a selector widget in django form

I want to create a form widget like the permission selector in the admin page. The model where i want to choose the records is a view from the database class Ftp_Archivo(models.Model): id_lista = models.IntegerField(primary_key=True) …
joselegit
  • 533
  • 1
  • 14
  • 35
2
votes
2 answers

Django. How to connect drop-down list (from html) and forms?

A have a field in model (name model is Users_data): bir_date = models.DateField(verbose_name="") And form which represents model: class Form_registration (ModelForm): class Meta: model = Users_data in html:
2
votes
1 answer

Customize the styles of Django ClearableFileInput widget

I have use ImageField in my django model to have the image upload facility. ImageField uses the ClearableFileInput widget but it does not provide well formatted html markup that i can customize using CSS. Shown bellow is the html markup that…
PIKP
  • 753
  • 2
  • 15
  • 24
2
votes
2 answers

Django: How to get the selected value from a custom widget?

I'm writing a custom Form widget that overrides the choice method in django.forms.models.ModelChoiceIterator: class CustomIterator(ModelChoiceIterator): …
3cheesewheel
  • 9,133
  • 9
  • 39
  • 59
2
votes
1 answer

Dynamic MultiValueField in Django

I am trying to create a custom widget based on a MultiValueField that dynamically creates its fields. Something along the lines of: class MyField(MultiValueField): def __init__(self, my_param, *args, **kwargs): fields = [] for…
mzu
  • 759
  • 8
  • 20
2
votes
1 answer

Customize ckeditor in django admin form

I need configure custom params (toolbars, width and height) of ckeditor for only one field in my AdminForm class BlogAdminForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(BlogAdminForm, self).__init__(*args, **kwargs) …
Dmitry
  • 551
  • 6
  • 19
2
votes
0 answers

Django CheckBoxSelectMultiple: individual checkbox initial values

For a given field, is it possible to have all boxes initially checked, but one? Currently I am using: widget=forms.CheckboxSelectMultiple({'checked':'checked'}) to have all checkboxes initially checked. Is there a way to set this for each checkbox…
bsuire
  • 1,383
  • 2
  • 18
  • 27