Created
May 11, 2016 14:48
-
-
Save kezabelle/b9c1e617966ffebfb16d77e43892aa91 to your computer and use it in GitHub Desktop.
for drvid on #django IRC.
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
class UserFormSet(BaseInlineFormSet): # or whatever. They all have __init__ and _construct_form and _empty_form | |
def __init__(self, user, *args, **kwargs): | |
self.user = user | |
super(UserFormSet, self).__init__(*args, **kwargs) | |
# Note: in master, at least, this is is all unnecessary, because there's a | |
# get_form_kwargs method you can use instead of either of these methods. | |
def _construct_form(self, i, **kwargs): | |
kwargs.update(user=self.user) | |
return super(UserFormSet, self)._construct_form(i, **kwargs) | |
def _get_empty_form(self, **kwargs): | |
kwargs.update(user=self.user) | |
return super(UserFormSet, self)._get_empty_form(**kwargs) | |
empty_form = property(_get_empty_form) | |
formset = inlineformset_factory(parent_model=Something, model=Something, formset=UserFormSet, form=MyMagicForm) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment