Django Mixin to pass extra attributes in form

Django -- Posted on July 17, 2017

Django Mixin to pass extra attributes in form

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

Related Posts