4

是否可以将多个模型传递给UpdateView?

就像是:

models = (FirstModel, SecondModel)
4

1 回答 1

9

不是通过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
于 2013-07-10T07:56:42.077 回答