Last active
July 5, 2017 19:20
-
-
Save danjac/10e9e21d3da34324a779b8a5cc50caf2 to your computer and use it in GitHub Desktop.
This file contains 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 .layout import FormHelper, FormHelperMixin | |
class MyForm(FormHelperMixin, forms.ModelForm): | |
class FormHelperMeta: | |
# works like Meta, we just use to store property overrides | |
# doesn't need to inherit | |
# helper_class = MyCustomHelper | |
submit_text = "Submit!" | |
action = reverse('account:login') | |
class Meta: | |
model = MyModel | |
# layouts.py | |
class EmptyHelperMeta: | |
pass | |
class FormHelperMixin(object): | |
def __init__(self, *args, **kwargs): | |
self.helper = self.get_form_helper() | |
def get_form_helper(self): | |
meta = getattr(self, 'FormHelperMeta', EmptyHelperMeta) | |
helper_cls = getattr(meta, "form_helper", FormHelper) | |
helper = helper_cls() | |
helper.form_method = getattr(meta, "method", "POST") | |
# etc etc | |
return helper | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment