Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple models in UpdateView

Is it possible to pass multiple models into the UpdateView?

Something like:

models = (FirstModel, SecondModel)
like image 493
Dmitrijs Zubriks Avatar asked Jul 25 '26 06:07

Dmitrijs Zubriks


1 Answers

Not via the models attribute for UpdateView.

But what you can do is either utilize extra_context or override the get_context_data() and add the models there.

An example of one such override would be:

class TaffyUpdateView(UpdateView):

    def get_context_data(self, **kwargs):
        context = super(TaffyUpdateView, self).get_context_data(**kwargs)
        context['second_model'] = SecondModel.objects.get(id=1) #whatever you would like
        return context
like image 62
Henrik Andersson Avatar answered Jul 28 '26 05:07

Henrik Andersson