Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django form widget

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

Django form example

from django import forms

# creating a form
class SampleForm(forms.Form):
	name = forms.CharField()
	description = forms.CharField()
Comment

PREVIOUS NEXT
Code Example
Python :: python read string from file 
Python :: python copy file to new filename 
Python :: python counter least common 
Python :: python datetime difference in seconds 
Python :: discord.py get profile picture 
Python :: get biggest value in array python3 
Python :: pyspark case when 
Python :: add element to list python at index 
Python :: python trace table generator 
Python :: python create virtualenv 
Python :: bot ping discord.py 
Python :: python delete file with extension 
Python :: python regex find first 
Python :: scrfoll with selenium python 
Python :: nltk in python 
Python :: python catch sigterm 
Python :: python hello world 
Python :: python ignore unicodedecodeerror 
Python :: discord py color 
Python :: pyhton regex to find string in file 
Python :: format string to 2 decimal places python 
Python :: if django 
Python :: read live video from usb opencv python 
Python :: extract column numpy array python 
Python :: lock in python 
Python :: map object to array python 
Python :: tkinter radio buttons 
Python :: install pip with pacman linux 
Python :: pip install django rest framework 
Python :: remove particular row number in pandas 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =