我有一个 modelformset AddressFormSet = modelformset_factory(Address)
。在我看来,我将此表单集分配给不同的上下文变量,但它们似乎是重复的。输入名称相同。
def get_context_data(self, **kwargs):
context = super(TravelCreate, self).get_context_data(**kwargs)
if self.request.POST:
context['address1'] = AddressFormSet(self.request.POST)
context['address2'] = AddressFormSet(self.request.POST)
else:
context['address1'] = AddressFormSet(queryset=self.model.objects.none())
context['address2'] = AddressFormSet(queryset=self.model.objects.none())
return context
如何给它们不同的名称,以便来自两个表单集的数据创建对象。