Answer the question
In order to leave comments, you need to log in
How to connect CreateView and UpdateView?
I have a custom form. It has two dynamic Select Boxes. The content of one depends on the URL, the second - on the first through an API request. In order to form the form, I got a large CreateView class. In it, for example, the URL is processed (dispatch), auxiliary data is added to the data incoming from the form before being written to the database (form_valid), etc.
class CostCreate(CreateView):
def dispatch(self, request, *args, **kwargs):
try:
self.type_of_cost = kwargs['type_of_cost']
except KeyError:
self.type_of_cost = 'daily'
def form_valid(self, form):
f = form.save(commit=False)
f.type = self.type_of_cost
f.save()
return super().form_valid(form)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question