Created
October 30, 2013 07:58
-
-
Save night-crawler/7228724 to your computer and use it in GitHub Desktop.
A small gist to change all django's default formfield widgets to floppyforms.widgets via widgets=floppyforms_widgets(YourModel) in ModelForm's Meta.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.forms.models import fields_for_model | |
| import floppyforms | |
| def widgets_for_model(model): | |
| return {k: v.widget.__class__.__name__ for k, v in fields_for_model(model).items()} | |
| def floppyforms_widgets(model): | |
| return {field: getattr(floppyforms, widget) for field, widget in widgets_for_model(model).items()} | |
| # Example: | |
| class CompanyEditForm(forms.ModelForm): | |
| class Meta: | |
| model = Company | |
| widgets = floppyforms_widgets(Company) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment