Django通用CBV模型及其相关的其他模型集?

时间:2018-09-07 00:13:45

标签: python django django-forms django-class-based-views

我有一个通用的Django CBV,如下所示:

class EditQuestion(LoginRequiredMixin, UpdateView):
    """
    Edit a specified question
    """
    model = Question
    fields = ['question_text']
    template_name = 'clients/business/update_question.html'

    def get_queryset(self):
        queryset = super(EditQuestion, self).get_queryset()
        queryset = queryset.filter(business__client=self.request.user)
        return queryset

    def form_valid(self, form):
        form.save()
        return HttpResponseRedirect(reverse('clients:question_list'))

每个问题都有一个名为Answer的不同模型的answer_set。如何在同一UpdateView中包含每个问题的answer_set?假设相关名称为answer_set

我实际上想将字段更改为fields = ['question_text', 'answer_set'],但是我知道那是不正确的。我想要一个包含问题及其答案集的表格(来自不同模型),我该怎么做?我认为人们必须一直以自己的形式进行操作。

0 个答案:

没有答案