django-widget

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

Override the template of a widget and pass values to it with Django 4.0 Question: 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 = models.CharField() manufacturere = models.ForeignKey(Manufacturer) class Review(models.Model): title = …

Total answers: 1

How do I get rid of labels in django Form?

How do I get rid of labels in django Form? Question: 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 …

Total answers: 1

TypeError: __init__() got an unexpected keyword argument 'attrs'

TypeError: __init__() got an unexpected keyword argument 'attrs' Question: I know this question had been asked many times but I still cant figure it out yet. from django.contrib.auth.forms import UserCreationForm from django.forms import ModelForm from django import forms from . models import Profile from django.contrib.auth.models import User ACCOUNT_TYPE = [ (‘SPO’, ‘SPO’), (‘Call Agent’, ‘Call …

Total answers: 2

How to change size of CharField

How to change size of CharField Question: This code is changing sizes of all CharFields in class. How I can change size of one CharField? formfield_overrides = { models.CharField: {‘widget’: TextInput(attrs={‘size’: ’20’})}, } Asked By: SBrain || Source Answers: Define a custom model form that overrides the widget for your field: from django import forms …

Total answers: 2

Specify max and min in NumberInput widget

Specify max and min in NumberInput widget Question: I have a form that is using NumberInput widget to accept a rating for a Song from the user. The number should be between 0-5. My Song model has a MaxValueValidator but I want the NumberInput widget to show options only from 0-5. Asked By: Darshan Chaudhary …

Total answers: 2

Django simple form "object has no attribute 'is_hidden'"

Django simple form "object has no attribute 'is_hidden'" Question: I’m trying to render a simple form with no db models but I am getting error. Following is the code: from django import forms from django.utils.safestring import mark_safe class ContactForm(forms.Form): category_options = ( (‘select category’, ‘–Select Category–‘), (‘fire safety’, ‘Fire Safety’), (‘batteries/solar panels’, ‘Batteries/Solar Panels’), ( …

Total answers: 3

Grouping CheckboxSelectMultiple Options in Django

Grouping CheckboxSelectMultiple Options in Django Question: In my Django App I have the following model: class SuperCategory(models.Model): name = models.CharField(max_length=100,) slug = models.SlugField(unique=True,) class Category(models.Model): name = models.CharField(max_length=100,) slug = models.SlugField(unique=True,) super_category = models.ForeignKey(SuperCategory) What I’m trying to accomplish in Django’s Admin Interface is the rendering of Category using widget CheckboxSelectMultiple but with Category somehow …

Total answers: 2

Django Admin: Using a custom widget for only one model field

Django Admin: Using a custom widget for only one model field Question: I have a DateTimeField field in my model. I wanted to display it as a checkbox widget in the Django admin site. To do this, I created a custom form widget. However, I do not know how to use my custom widget for …

Total answers: 5