I am using Django and Datepicker together with Twitter-Bootstrap and I want the form.fields to have same class and same id if they are of same widget(DateInput). In specific, i would like to change the id accordingly. It should have a different id every time.
This is the class i defined below. How do i change the id to be a different one every time.
class MyDatePicker(forms.DateInput)
def __init__(self, *args, **kwargs):
attrs = kwargs.pop("attrs",{})
attrs["class"] = "datepick"
attrs["id"] ="date_1"
kwargs["attrs"] = attrs
super(MyDatePicker, self).__init__(*args, **kwargs)
How do i go about doing it?Need some help on it…Would welcome any suggestion…
You could register a templatetag to find out the widget type:
Then in your template:
Note: A cleaner DRY approach would be to add the loop and class logic (horizontal/vertical etc) to a filter returning a html widget