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

How can I implement the same widget that Django uses to ManyToMany fields in the admin page?

My models: class Ingredient(models.Model): BASE_UNIT_CHOICES = [("g", "Grams"), ("ml", "Mililiters")] CURRENCY_CHOICES = [("USD", "US Dollars"), ("EUR", "Euro")] ingredient_id = models.AutoField(primary_key=True) name =…
Guillermo
  • 7
  • 2
0
votes
0 answers

How do I add a class to a custom widget?

I've defined the following custom widget in forms.py, which over rides the standard HTML to create a "live search" select menu (user can enter free text to search options, useful when there are many options). For this widget to work, the…
rcx935
  • 217
  • 5
  • 15
0
votes
1 answer

render a CharField as checkbox in Django admin?

Is it possible to render a Django model CharField as a checkbox? I need this checkbox on admin edit page as well as the list_editable list page. E.g. when checked, set this CharField value to 't', else set it to 'n'
est
  • 11,429
  • 14
  • 70
  • 118
0
votes
1 answer

Modify django model form field with widget

I want to modify some fields in model form, and i found two methods: First Method: class ProfileForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) …
penk
  • 197
  • 1
  • 3
  • 14
0
votes
1 answer

Using jQuery DateTimePicker in Django Admin (jazzmin) get error - Enter a list of values

Plugged in TempusDominus widget for DateTimeField in Django admin. The task is to enable date selection with scaling by months and years. The standard widget doesn't have that option. But Django, when using DateTimeField, expects to return two…
0
votes
2 answers

How to find out current logged-in user in widget in Django Wagtail

I have been looking for a way to find out who the current logged-in user is in Django Wagtail so that I could create a widget to render a base setting field to be editable/non-editable. I was able to get some basic logic working but couldn't figure…
leol
  • 37
  • 6
0
votes
1 answer

Django Widgets with Bootstrap

I am trying to stylize my form using bootstrap. As you know bootstrap uses a lot of classes in order to do what it does. By googling I have found to inject some new classes into my form I could use widgets with django. My form is as follows: class…
mharre
  • 233
  • 3
  • 17
0
votes
1 answer

django django-yearmonth-widget display month as month name

I have used package "django-yearmonth-widget" to have year and month selection and not complete date. Here, day is fixed i.e. 1st of every month. This implementation is working fine. Package: pip install django-yearmonth-widget Problem I am facing…
Ronak
  • 187
  • 2
  • 17
0
votes
1 answer

Is there Django form field or widget that appends Radio and CharField

I'm trying to create a Django form fields that has radio choices and "other" choice that is a text field. It should look like this I tried this but its from 2014 and it's not working. Can you give me an idea how to fix this code or how can I create…
0
votes
1 answer

Is there a 'SelectDateTime' widget for django forms?

Basically the same as the SelectDate Widget but with an hour component as well. Can't seem to find one in the official docs?
super9
  • 29,181
  • 39
  • 119
  • 172
0
votes
1 answer

using widgets to change the CSS of label in Django forms

I am trying to apply CSS styling to the admin login form in Django (version 3.1.3). I am able to customise the inputs easily enough using Widgets via the forms.TextInput(attrs={'class':'textinputclass'}) method however there seems to be no way to…
Ramirez100
  • 17
  • 1
  • 8
0
votes
1 answer

Error -Undefined variable: 'ModelSelect2Widget'

I am new to this field. I am working on Dependent Dropdowns for which i took reference from here. On replicating the same with the following code: Forms.py class AddressForm(forms.ModelForm): class Meta: model=City country =…
Ritu
  • 1
  • 1
0
votes
1 answer

How to print post data on the same web page?

I am trying to print the POST data from django form on my webpage, right under my form. I am able to print it by HttpResponse on a different page, but I want it on the same page when the user presses submit button. Views.py from…
0
votes
1 answer

Django - Enter a list of values - ForeignKey

For a M2O relation what field should I be using in forms? models.py class Studio(models.Model): name = models.SlugField(max_length=100) rating = models.CharField(max_length=10, default=None) def __str__(self): return…
0
votes
1 answer

How to use sekizai's addtoblock tag inside a form widget template

I am writing a custom form field which has a custom widget. The widget needs some static assets. Its template looks like this: {% load sekizai_tags static %}
...
{% addtoblock "css" %}
fekioh
  • 894
  • 2
  • 9
  • 22