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 to add Value to django Markitupwidget?

How to add value to this "form.content" before rendering class myform(forms.Form): title = forms.CharField(max_length = 30) content = forms.CharField(widget=MarkItUpWidget()) tag = forms.CharField(max_length = 30)
user1288625
  • 15
  • 1
  • 5
0
votes
2 answers

How to add default value to django-markitup widget?

Friends,I want to add default value to django MarkItUpWidget title = forms.CharField(max_length = 30) content = forms.CharField(widget=MarkItUpWidget())
0
votes
2 answers

Django: custom content in admin form

For one of my models, I want to show extra content in the change_form. Basically, my model looks like this: class News(models.Model): ... class NewsFromSource(models.Model): news = models.ForeignKey(News) ... I want…
Joseph Tura
  • 6,290
  • 8
  • 47
  • 73
0
votes
1 answer

How to link to a new model instance creation page related to the currently viewed instance

I have some Django models with a structure similar to this: class Grandparent(models.Model): name = models.CharField(max_length=80) class Parent(models.Model): name = models.CharField(max_length=80) grandparent =…
Ohad
  • 1,719
  • 1
  • 16
  • 20
0
votes
2 answers

django custom field and widget

Im writing a custom field/widget to display multiple input fields for related data, for example my product has 4 search fields, search1, search2, search3, etc.. , instead of having to define each field in my form, i want to have one field that will…
Paulo
  • 6,982
  • 7
  • 42
  • 56
0
votes
0 answers

How to upload multiple images or files in a single input field using Django forms?

I'm working on a Django project and I need to implement a feature where users can upload multiple images or files through a single input field in a Django form I attempted to implement the MultiFileInput widget from the django-multiupload package…
0
votes
1 answer

How to update widget attribute based on user role in Django

I have this custom widget: class RelatedFieldWidgetCanAdd(widgets.Select): def __init__(self, related_model, related_url=None, can_add_related=True, *args, **kw): self.can_add_related = can_add_related …
Ankit Tiwari
  • 4,438
  • 4
  • 14
  • 41
0
votes
0 answers

Django form image field mandatory error even when filled

I have a form that works both for when creating a new instance or editing one, on django. The problem is that no matter what scenario, even when I fill the input file fields, it always returns error that fields are mandatory. The models.py: class…
Fabíola
  • 116
  • 1
  • 5
0
votes
1 answer

How to use Many to Many widget presented in Admin page

I want to use the widget presented in Admin page for Group creation in my Modelform (picture below) but I'm failing in do that. Does anyone know how can I use a widget like this in my form? I have two models that have a many-to-many relationship. I…
0
votes
1 answer

Override the template of a widget and pass values to it with Django 4.0

I am creating a simple app to do product reviews. I have a Product, Manufacturer and Review models which I will now summarize class Manufacturer(models.Model): name = models.CharField() class Product(models.Model): name =…
0
votes
0 answers

Styling a GeoDjango widget

I have been trying to style the GeoDjango OSMWidget (for Polygon drawing) for ages but can't work out how to make it flexible. Setting the map width and map height is all fine for a fixed page size but what happens if someone snaps their browser…
obrunt
  • 125
  • 7
0
votes
0 answers

CheckboxSelectMultiple widget Django renders already collapsed in form

I am trying to create a form where you can enter the language or languages. I want to use a CheckboxSelectMultiple widget, but it renders already collapsed in the form: The form with already collapsed select How can I fix this? forms.py: class…
0
votes
1 answer

"formfield_overrides" vs "formfield_for_dbfield()" vs "form" vs "get_form()" to change the width of the field in Django Admin

For example, there is Person model below: # "models.py" from django.db import models class Person(models.Model): name = models.CharField(max_length=20) age = models.PositiveSmallIntegerField() def __str__(self): return…
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
0
votes
0 answers

Styling prefilled Django radio input as buttons

I have a Django form field that is prefilled and using widget gave it a class. The form is rendered out in html as
0
votes
1 answer

Django's Generic UpdateView: How to pass value to the hidden form field?

I am trying to combine Django's generic UpdateView and hidden input field. My purpose is to track whether a post was edited after it was created or not. Hidden field name is "updated". views.py: class PostUpdateView(UpdateView): model = Post …