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

get new value in django admin widget

I am working on creating a widget so clients can easily modify model's Json field in django admin. Env Info: django-version: 3.1.14 Before drive into the widget, this is a simplify version of my model: class Property(PolymorphicModel): """Basic…
0
votes
0 answers

Django does not add attribute to the custom ModelForm widget

I'm trying to add another attribute in HTML (placeholder) using Django Widgets, when I do it, they don't appear in the HTML. models.py class InvitadosIngreso(forms.ModelForm): class Meta: model = InvitadosIngreso fields =…
TrueAFM
  • 27
  • 4
0
votes
1 answer

How do I get rid of labels in django Form?

I have dealt with only ModelForm previously, so it is my first time using Form. I'd like to get rid of labels from my form, however, how I get rid of labels in ModelForm does not seem to work with Form. Here is my code: forms.py class…
gtj520
  • 196
  • 1
  • 10
0
votes
0 answers

Django - why my widget is cleared out during save?

I'm struggling with a django custom widget used to present HTML data. I've started with a template from standard django's textarea: class Descriptionarea(forms.Widget): template_name = "widgets/descriptionarea.html" def __init__(self,…
user3193620
  • 173
  • 1
  • 11
0
votes
1 answer

How to use JavaScript client-side encryption/decryption in django forms / crispy forms? Is there any python package available which can do this

Django Form fields needs to be encrypted at server side and needs to be decrypted in client browser while rendering and vice versa for form submission One approach is using JS cryptographic libraries or to use custom encryption code. But, Is there…
0
votes
1 answer

django-filter looking for templates only in venv

Tried to make custom widget for RangeFilter. Every time django raises TemplateDoesNotExist Template-loader postmortem Django tried loading these templates, in this order: Using engine django: django.template.loaders.filesystem.Loader:…
0
votes
0 answers

Can I create Django widgets at an own discretion?

There is a widget in Django, called NumberInput, the type of which can be defined as range. It is an usual range. There is a graphical element – a slider (a range as well) in a website. That's convenient that it has an animated label with number…
SFriendly
  • 119
  • 3
0
votes
1 answer

How to auto populate a field in django when a value is selected from dropdown menu in another field in forms?

I have two models that are located in two different apps; Invoice and Inventory. InvoiceModel: class Invoice(models.Model): line_one = models.ForeignKey(Inventory, to_field='title', on_delete=models.CASCADE, default='', blank=True, null=True,…
0
votes
1 answer

change field type in django forms

I have a model for a group that has two fields: leader and description. models.py class Group(models.Model): leader = models.ForeignKey(User, on_delete=models.CASCADE) description = models.TextField() forms.py class…
0
votes
1 answer

Django template tag show value not key

This is probably a simple answer, but I can't seem to find it in the docs. How do I display the value of a choice field in template tags? Using .value did not work as I thought it may. Right now it's just displaying the Key: user_update when I call…
0
votes
1 answer

forms.Select(attrs={'class': 'form-control' Edit form and get numbers 1-5 in dropdown

Am wondering how i can get this html code into a forms.py in my ReviewForm as widgets. This code: 'rating': forms.Select(attrs={'class': 'form-control',}), Should be as the html code under with 1-5. And also be saved in models so the rating still…
0
votes
1 answer

How can I add Datepicker in DjangoCreateView

#view.py class JobCreateView(CreateView): model = Job template_name = 'Job_create.html' fields = ['Company' ,'Job_title','Department','Start_date','end_date','Consent'] def form_valid(self, form): form.instance.Alumni_id =…
0
votes
1 answer

Resizing TinyMCE in django

I am trying to write a widget to resize my django tinymce but it doesn't seem to work... Does anyone know what the problem is with this code snippet? from django import forms from .models import blog, comment, reply, like, subscription from…
BJ_GOST
  • 31
  • 2
0
votes
0 answers

Django Custom Password Reset Form widget not working

Stumped as to why my template isn't showing my custom password reset form. Here is code: forms.py class CustomPasswordResetForm(PasswordResetForm): def __init__(self, *args, **kwargs): super(CustomPasswordResetForm, self).__init__(*args,…
0
votes
1 answer

SelectMultiple and OptionGroup in Django

I'm using option group-style choices for a django form field, like this: MEDIA_CHOICES = ( ('Audio', ( ('vinyl', 'Vinyl'), ('cd', 'CD'), ) ), ('Video', ( ('vhs', 'VHS Tape'), …
Jordan Reiter
  • 20,467
  • 11
  • 95
  • 161