dkoug Blog

Django Mixin to pass extra attributes in form

Django -- Posted on July 17, 2017

Django Mixin to pass extra attributes in form

1
2
3
4
5
6
7
8
class MyForm(object):

    def __init__(self, *args, **kwargs):
        super(MyForm, self).__init__(*args, **kwargs)
        for field in self.fields:
            if 'File' not in self.fields[field].widget.__class__.__name__:
                self.fields[field].widget.attrs.update(
                    {'class': 'form-control'})