I can't figure it out for the life of me. I don't think it's possible. Something so simple shouldn't be hard at all. Anyone?
views:
142answers:
3
+4
A:
Not sure what you're referring to. Do you mean an HTML <input> tag generated by django.forms? If so, just specify a custom widget, using the attrs attribute in the constructor. See docs.
michael
2009-08-28 19:01:36
Yes, that's what i mean. and i know about the attr object i can set. however, automatically generated forms from the django.models class doens't seem to allow for this.
Kenneth Reitz
2009-08-28 21:44:10
To customize the widget, declare the field in your form class. You have to do so for each field you want to add a class attribute to. See http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-default-field-types
michael
2009-08-29 01:45:44
+1
A:
You just need to override the relevant field in your form class, and add your attribute to the widget. This is described clearly in the documentation.
Daniel Roseman
2009-08-28 22:33:01
You must have a form class somewhere, even if it only has the meta `class=MyModel` declaration. Or did you mean a form generated within the admin? If so, please say so.
Daniel Roseman
2009-08-29 08:11:15
+1
A:
django-html provides a templatetag which allows you to add extra attributes in the template, like so:
{% field form.fieldname class="myclass" %}
insin
2009-08-30 16:07:21