I have used the SplitDateTimeWidget to override a field in my model form.
Is there a way for to assign css classes to the individual fields created by this?
widgets = {
'my_field': SplitDateTimeWidget(),
}
Any advice appreciated.
After I tried your code Brandon:
If I try it without passing attrs I get:
‘NoneType’ object is not iterable
for the line attrs_dict = dict(attrs).
If I do include attrs, I get:
‘tuple’ object has no attribute ‘copy’
at /usr/local/lib/python2.6/dist-packages/django/forms/widgets.py in init, line 147
Yes, you can pass in attrs={‘class’ : ‘your_class’}, but it will apply the class to both the DateInput and TimeInput.
If you’re needing to add a different class to both fields, you’ll probably need to extend SplitDateTimeWidget, override the init.
I’ve tested this in Django 1.3, which will output the following html when using that widget on a forms.DateTimeField called ‘test_field’:
I’ve tried various ways to copy the attrs that come in to preserve any other params that might be there, but I’m running into errors, and unfortunately I’ve run out of time for today. This should get you going, but will only allow you to modify the class attr of the fields.