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

Change the field class on error

I want to change the input field class and other attributes in case of error. So in form init : for f_name in self.fields: if f_name in self.errors: self.fields[f_name].widget.attrs['error'] = a else: …
user3541631
  • 3,686
  • 8
  • 48
  • 115
0
votes
2 answers

Django: Dynamically update ModelForm's Field widgets

I want to dynamically generate ModelForm's Meta Class widgets according to exercise_type field from Exercise class. How can I get the value? class ExerciseAdminForm(ModelForm): class Meta: model = Exercise fields =…
Mzq
  • 1,796
  • 4
  • 30
  • 65
0
votes
1 answer

Get all records data to a Widget without making a new Query in the database

I have 2 Models Product and Category with - ManyToMany Relation Product-Category and self ForeignKey for Category class Category(models.Model): parent = models.ForeignKey('self', blank=True, null=True, verbose_name='parent category',…
user3541631
  • 3,686
  • 8
  • 48
  • 115
0
votes
1 answer

Django Caught Warning while rendering: Incorrect integer value: ... for column 'user_id' at row 1

I am building a section for my site that allows hunters to write hunting reports. in this section they can choose from a 'wish list' (animals they would like to hunt) and 'bag list' (animals they have hunted) I have built the form, and need to make…
ApPeL
  • 4,801
  • 9
  • 47
  • 84
0
votes
2 answers

How to override template_name in SelectDateWidget (Django 1.11)

I need to wrap the fields in div. In Django 1.10: class CustomSelectDateWidget (SelectDateWidget): def render(self, name, value, attrs=None): ... output = [] for field in self._parse_date_fmt(): if field ==…
Stanislav
  • 59
  • 2
  • 7
0
votes
1 answer

Django admin widget for custom-sorted relationship

I need some help at designing a model and widget for a custom-sorted M2M relationship. The typical application scenario would be books and authors. In particular, when the order of authors in a book does matter. The current version of my Publication…
phretor
  • 57
  • 2
  • 9
0
votes
1 answer

Django: Check multiple choices with not fixed choices

I am new to Django, and I am trying to create a multiple selection with checkboxes. The problem is that all of the examples that I found have fixed choices that are specified in the form, and I don't need that. More concretely, let this be a model…
makons
  • 522
  • 1
  • 11
  • 27
0
votes
1 answer

DJango Model form that display's user.profile.name info instead user.username

I have a ModelForm in Django that is used to take attendance at an event. It displays the user as plain text instead of a field: class PlainTextWidget(forms.Widget): def render(self, name, value, attrs=None): return mark_safe(value) if…
43Tesseracts
  • 4,617
  • 8
  • 48
  • 94
0
votes
1 answer

How to use django raw_id_fields in a view?

I am making a view, to make some POST requests on my Django server. I need a way to select something and the proper widget that I need for the same is Django admin panel's raw_id_fields. Widget: Popup: I was looking for a jquery plugin to do the…
Ishan
  • 3,303
  • 5
  • 29
  • 47
0
votes
1 answer

How do I write my own Django form widget?

Could anyone provide a simple example, so that I understand the basic idioms of how this is done? I can't find any helpful documentation that I can understand on the topic. To provide a little more context, I'd like to create my own radio buttons,…
Jarrod
  • 1,655
  • 2
  • 21
  • 35
0
votes
1 answer

ManyToManyFields as IntegerFields in Django admin interface

Assuming I have : class Product(models.Model): [...] class Basket(models.Model): content = models.ManyToManyField(Product, through="ProductQuantity") class ProductQuantity(models.Model): basket = models.ForeignKey(Basket) product =…
vmonteco
  • 14,136
  • 15
  • 55
  • 86
0
votes
1 answer

The django-markdown-bootstrap-widget is not showing properly

I am django beginner and I have the following Problem. I want to define a model and us this model to generate a form with the markdown-widget. https://github.com/MSA-Argentina/django-bootstrap-markdown Model class ThesisAnmeldung(models.Model): …
Julian
  • 15
  • 2
0
votes
3 answers

wrap html tags to make all clickable

I'm looking to turn an entire row clickable. Right now the rows look like
codyc4321
  • 9,014
  • 22
  • 92
  • 165
0
votes
2 answers

Defer execution of widget js until page is fully loaded

I have a widget with some custom js: class ImagePreviewWidget(ClearableFileInput): ... class Media: css = { 'all': ('css/image-preview-widget.css',) } js = ('js/image-preview-widget.js', ) The custom…
blueFast
  • 41,341
  • 63
  • 198
  • 344
0
votes
0 answers

How to insert Checkbox in django

hallo i want to create data with checkbox field but data cannot save in database when i use widget RadioSelect this is forms.py class VehicleAttribute(forms.ModelForm): OPERATION = [('production','Production Vehicle'),('supporting','Supporting…
User0511
  • 665
  • 3
  • 11
  • 27