tags:

views:

142

answers:

3

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?

+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
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
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
+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
there is no form class. it's a model class.
Kenneth Reitz
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
+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