I have a url of the form:
path('makeoffer/<listing_id>', OfferCreateView.as_view(), name="CreateOfferview"),
This view is a form, with a couple of parameters. The listing_id needs to be saved as part of the Offer object, and is not user-editable. I essentially want to do this:
def form_valid(self, form):
form.instance.user = self.request.user
form.instance.datetime = dt.now()
form.instance.listing_id = listing_id #(from the url)
How do I access the parameter from inside the form_valid function? I've tried get_context_data, but the only way I could see to do it would be for the get_context_data to pass it to the view, and then have the view pass it back to the form, which seems a bit hacky.