是否可以将多个模型传递给UpdateView
?
就像是:
models = (FirstModel, SecondModel)
不是通过models
.UpdateView
但是您可以做的是利用extra_context
或覆盖get_context_data()
并在那里添加模型。
一种此类覆盖的示例是:
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