Reputation: 123
Is there anyway to pass an argument in to a model FormView using django crispy forms?
I'm setting the url like:
self.helper.form_action = reverse(my_url, args={'pk': self.instance.pk})
I even tried overriding get_form()
by doing:
form = super().get_form(form_class)
form.helper.form_action = reverse(my_url, args={'pk': self.kwargs.get('pk')})
and neither of those worked I keep getting an error thrown saying there is no reverse match where the pk
argument is blank.
I realize I could just set this in the template, but I'm using an abstract template which also works for loading the form (and just the form) dynamically into modals so that would require me to restructure all of this.
Upvotes: 2
Views: 1091
Reputation: 27523
form.helper.form_action = reverse('url_name', args=[self.instance.id])
or
form.helper.form_action = reverse('url_name', kwargs={'pk': self.instance.id})
Upvotes: 4