Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django widgets

from django import forms

class ProductForm(forms.ModelForm):
  	### here date is the field name in the model ###
    date = forms.DateTimeField(widget=forms.DateInput(attrs={'class': 'form-control'}))
    class Meta:
        model = Product
        fields = "__all__"
        
############## or ##############

class ProductForm(forms.ModelForm):
    class Meta:
        model = Product
        fields = "__all__"
        
    def __init__(self, *args, **kwargs):
        super(ProductForm, self).__init__(*args, **kwargs)
        self.fields['date'].widget.attrs["class"] = "form-control"

############## or ##############

class ProductForm(forms.ModelForm):
    class Meta:
        model = Product
        fields = "__all__"
		widgets = {
            'date': forms.DateInput(attrs={'class': 'form-control'})
        }
### you can use the attrs to style the fields ###
Comment

PREVIOUS NEXT
Code Example
Python :: django dumpdata 
Python :: pandas datetime.time 
Python :: no migrations to apply django 
Python :: percentage of null values for every variable in dataframe 
Python :: convert array to list python 
Python :: how to write your first python program 
Python :: program to tell if a number is a perfect square 
Python :: get last day of month python 
Python :: python get dict values as list 
Python :: flask_mail 
Python :: latency discord.py 
Python :: python requests with login 
Python :: how to separate a string or int with comma in python 
Python :: python tkinter askopenfile 
Python :: how to playsound in python 
Python :: python __gt__ 
Python :: how to print on python 
Python :: convert a tuple into string python 
Python :: label encoding column pandas 
Python :: np shuffle 
Python :: pandas append index ignore 
Python :: how to create requirements.txt django 
Python :: sorting by second element 
Python :: show all columns pandas jupyter notebook 
Python :: use datetime python to get runtime 
Python :: python datetime no milliseconds 
Python :: df empty 
Python :: Write a python program to find the most frequent word in text file 
Python :: python subprocess with environment variables 
Python :: python reverse linked list 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =