Решил таким образом:
from django.forms import inlineformset_factory
class QCWorkConstructionCreateView(TemplateView):
template_name = 'executive/qc/qc-work-construction-create.html'
def get_context_data(self, **kwargs):
context = super(QCWorkConstructionCreateView, self).get_context_data(**kwargs)
works = Work.objects.filter(id__in=self.request.GET.getlist('works'))
# задаем начальные значения
initial = []
for work in works:
for con in work.constructions.all():
qc_con = dict()
qc_con['construction'] = con.id
qc_con['work'] = work.id
qc_con['value'] = ''
initial.append(qc_con)
# количество отображаемых строк formset
extra = len(initial)
# форма для документа QC
form = QCForm(self.request.user, {'object': self.request.user.profile.current_object_id})
# Formset для QCConstruction
QCformset = inlineformset_factory(QualityControl, QCConstruction, fields=('construction', 'work', 'value',), extra=extra)
context['form'] = form
context['formset'] = QCformset(initial=initial)
return context
def post(self, *args, **kwargs):
form = QCForm(self.request.user, self.request.POST)
if form.is_valid():
qc = form.save()
QCformset = inlineformset_factory(QualityControl, QCConstruction, fields=('construction', 'work', 'value',))
formset = QCformset(self.request.POST, instance=qc)
if formset.is_valid():
formset.save()
return redirect('qc_list')