-
-
Save rudmanmrrod/db6f592a619b7c7a439a32ea8f831182 to your computer and use it in GitHub Desktop.
Django: pass a variable from a form view to a form
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 MyForm(forms.ModelForm): | |
requested_asset = None | |
def __init__(self, *args, **kwargs): | |
other_variable = kwargs.pop('other_variable') | |
super(MyForm, self).__init__(*args, **kwargs) |
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 MyCreateView(CreateView): | |
model = MyModel | |
template_name = 'myapp/my_form.html' | |
form_class = MyForm | |
other_variable = None | |
def get_form_kwargs(self): | |
kwargs = super(MyCreateView, self).get_form_kwargs() | |
kwargs.update({'other_variable': self.other_variable}) | |
return kwargs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment