Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django ModelForm style

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 :: accessing dictionary elements in python 
Python :: random hex color python 
Python :: boxplot pandas 
Python :: python join list to string 
Python :: pandas convert date to quarter 
Python :: how to copy one dictionary to another in python 
Python :: filter dataframe 
Python :: ffmpeg python cut video 
Python :: run python file in interactive mode 
Python :: python read zipfile 
Python :: create dictionary comprehension python 
Python :: delete files with same extensions 
Python :: python add to list with index 
Python :: python get response headers 
Python :: install nltk in python 
Python :: set image size mapltotlib pyplot 
Python :: python3 hello world 
Python :: while not equal python 
Python :: load saved model tensorflow 
Python :: list of df to df 
Python :: Add new column based on condition on some other column in pandas. 
Python :: how to change role permissions in discord.py 
Python :: python weekday 
Python :: export pythonpath linux 
Python :: python convert dictionary to pandas dataframe 
Python :: python how to change an element in a multi dimensional list 
Python :: password manager python 
Python :: convert string in list format to list python 
Python :: django rest 
Python :: uniform distribution python example 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =