I hope I understand what you're asking: that you want to add a CSS
class to each form field generated by the form_for_* helpers?

If so, you could make a small `base class`_ to do that::

    class BaseYourForm(forms.BaseForm):
        def __init__(self, *args, **kwargs):
            super(BaseYourForm, self).__init__(*args, **kwargs)
            for i in self.fields:
                self.fields[i].widget.attrs['class'] = 'yourclassname'

Then just create your form with that one extra argument::

    YourForm = form_for_model(YourModel, form=BaseYourForm)

There may be a better way to do that, but it works for me. :-)

Don't forget about the `fields argument`_ if you only want a few of
your model's fields to show up in the form::

    YourForm = form_for_model(YourModel, fields=dictOfYourFields,
                              form= BaseYourForm)

.. base class: 
http://www.djangoproject.com/documentation/newforms/#using-an-alternate-base-class
.. fields argument: 
http://www.djangoproject.com/documentation/newforms/#using-a-subset-of-fields-on-the-form

Cheers.
- whiteinge



On Jun 24, 12:47 pm, l5x <[EMAIL PROTECTED]> wrote:
> Hello,
>
> is there any possibility in django to put a widget into a model
> instead of creating the whole forms for each model (using widgets
> render)? I only need to add a css class to each field in a model...
>
> Best regards


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to