Dimitris Kougioumtzis Blog About technology

Django Mixin to pass extra attributes in form

Category 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'})

About

My name is Dimitris Kougioumtzis and i work as a Web developer at Rapidbounce Company

Elsewhere