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
1 answer

Add CSS class to entire form in Django

Suppose I have a form: class MyForm(forms.Form): ... and then in a view I construct it: ... form = MyForm() ... I would like to add a CSS class to the entire form, so that I can render it as something like this:
jazzblue
  • 2,411
  • 4
  • 38
  • 63
2
votes
1 answer

How to create a custom date time widget for the django admin?

My Problem: I have a model that accepts DateTimeField. The user enters this from the django-admin. But, I cant get a way to get the user's local timezone. So my best shot is forcing the user to enter the date-time in UTC. But for the users…
Indradhanush Gupta
  • 4,067
  • 10
  • 44
  • 60
2
votes
2 answers

FilteredSelectMultiple widget on field feincms content type

I have a custom made content type in FeinCMS. class DownloadsContent(models.Model): title = models.CharField(max_length=200, verbose_name=_('title')) files = FileManyToMany(verbose_name=_('files')) The 'files' field is an manytomany which…
nelsonvarela
  • 2,310
  • 7
  • 27
  • 43
2
votes
0 answers

need a time widget or clock widget

is there anything like a timewidget or clock widget in Django which will help me to input data into a form for appointment date (like we have calendar or date widget). i have my date widget working with the below code in my forms.py: import…
Malik Aqib
  • 513
  • 5
  • 21
2
votes
1 answer

selectdatewidget set default month and day

How can I set selectDateWidget day and month options to default as 1st January but leave the year option intact. Now I am doing: day = datetime.date.today() lessTime = forms.DateField(required=False, widget=SelectDateWidget(years=range(1980,…
Santiago
  • 1,984
  • 4
  • 19
  • 24
2
votes
1 answer

Django - Time range widget

I'd like to use jQueryUI Slider as a widget allowing to configure business hours. So I did this models: WEEKDAYS = [ (1, _("Monday")), (2, _("Tuesday")), (3, _("Wednesday")), (4, _("Thursday")), (5, _("Friday")), (6, _("Saturday")), …
Pierre de LESPINAY
  • 44,700
  • 57
  • 210
  • 307
2
votes
2 answers

Render widget in django template

I have an awesome widget to display information, and I want to use it in a template but without using a form. My template is used only to display info, there is no form to be submited. How can I render this widget in a template without using a form.…
danielrvt
  • 10,177
  • 20
  • 80
  • 121
2
votes
1 answer

How to change year options of django's selectDateWidget

I want to use django's selectDateWidget for a form but the options for years are from 2012-2021. I need to display past years and probably up to 1980. How can I modify selectDateWidget? lessTime = forms.DateField(required=False,…
Santiago
  • 1,984
  • 4
  • 19
  • 24
2
votes
1 answer

Override a Django form field from a different app

Django Guardian has two forms defined in admin.py, GroupManage and UserManage: https://github.com/lukaszb/django-guardian/blob/master/guardian/admin.py#L368 I would like to add auto-completion to these two forms, and the best way I assume to make…
zgohr
  • 678
  • 7
  • 8
2
votes
1 answer

Django - DateTime Widget format

I'm trying to implement a DateTimePicker Widget. Widget class DateTimeWidget(forms.DateTimeInput): class Media: js = ('js/jquery-ui-timepicker-addon.js',) def __init__(self, attrs=None): if attrs is not None: self.attrs =…
Pierre de LESPINAY
  • 44,700
  • 57
  • 210
  • 307
1
vote
1 answer

Where does the widgets/foreign.html file reside in django trunk?

I would like to override (create custom) widgets/foreign.html template for a ForeignKey field but can't find this in the source. Browsing the Django SVN respository I can find these files at revision: 7966, but they are removed after this…
qhyzcjc
1
vote
0 answers

ModelMultipleChoiceField do not validate with widget attribute overrided to Select

From docs: ManyToManyField is represented by django.forms.ModelMultipleChoiceField, which is a MultipleChoiceField whose choices are a model QuerySet. From source: class ModelMultipleChoiceField(ModelChoiceField): """A MultipleChoiceField…
I159
  • 29,741
  • 31
  • 97
  • 132
1
vote
2 answers

Custom Django CheckboxSelectMultiple widget rendered as an empty list

I am trying to create a CheckboxSelectMultiple widget that lists all the content types of my project. I started by using the base widget when defining a MultipleChoiceField field in a ModelForm and it worked fine. I would like now to make it a…
Dr Tuple
  • 23
  • 1
  • 4
1
vote
4 answers

django: SplitDateTimeWidget ignores date_format

I am trying to use the SplitDateTimeWidget but want it to accept date in day - month - year format. from django.forms.widgets import SplitDateTimeWidget class EventForm(forms.ModelForm): class Meta: model = Event widgets =…
onurmatik
  • 5,105
  • 7
  • 42
  • 67
1
vote
0 answers

How to change the widget for a computed field on a Django Admin model form

For a Django Admin model form, if you display a calculated field, is there a way to also specify the widget the form should used to display that field? I cannot seem to find any mention of this. All the examples I have found describe how to override…
Steve Wehba
  • 161
  • 1
  • 6