Skip to content

Instantly share code, notes, and snippets.

@aherok
Last active December 20, 2015 17:59
Show Gist options
  • Save aherok/6172929 to your computer and use it in GitHub Desktop.
Save aherok/6172929 to your computer and use it in GitHub Desktop.
BootstrappedMixin for form - adds Bootstrap3.0 classes & placeholder
class BootstrappedMixin(object):
def __init__(self, *args, **kwargs):
super(BootstrappedMixin, self).__init__(*args, **kwargs)
for field_name in self.fields:
field = self.fields.get(field_name)
attrs = {'class': 'form-control'}
if field and isinstance(field.widget, forms.TextInput):
attrs.update({'placeholder': field.label})
field.widget.attrs = attrs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment