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 ###
from django import forms
# creating a form
class SampleForm(forms.Form):
name = forms.CharField()
description = forms.CharField()