Я работаю на фабрике inlineformset все работает нормально, но formset хранилища данных только первое значение.
я использую formset.js файл для добавления строк.
родительская модель данные сохранены, но данные набора форм сохранены только информация о первой строке .
Вот мой код
forms.py
Вот мой код набора форм
SizeChartFormSet = inlineformset_factory(
TailoringProductsMaster, SizeChart, extra=1,
fields='__all__',
form =SizeChartForm,
can_delete=True,
widgets={'SizeType': forms.TextInput(attrs={'class':"form-control col-md-7 col-xs-12",}),
'RequiredFabric': forms.TextInput(attrs={'class': "form-control col-md-7 col-xs-12",}),
},
)
Views.py
Вот мой код просмотра
class TailoringProductsMasterCreateView(CreateView):
model = TailoringProductsMaster
form_class = TailoringProductsMasterForm
success_url = reverse_lazy('home')
def get_context_data(self, **kwargs):
context = super(TailoringProductsMasterCreateView, self).get_context_data(**kwargs)
if self.request.POST:
context['operations_form'] = SizeChartFormSet(self.request.POST, self.request.FILES)
else:
context['operations_form'] = SizeChartFormSet()
return context
def post(self, request, *args, **kwargs):
self.object = None
form_class = self.get_form_class()
form = self.get_form(form_class)
operations_form = SizeChartFormSet(self.request.POST, self.request.FILES)
if (form.is_valid() and operations_form.is_valid()):
return self.form_valid(form, operations_form)
else:
return self.form_invalid(form, operations_form)
def form_valid(self, form, operations_form):
self.object = form.save()
operations_form.instance=self.object
operations_form.save()
return HttpResponseRedirect(self.get_success_url())
def form_invalid(self, form, operations_form):
return self.render_to_response(
self.get_context_data(form=form, operations_form=operations_form ))
html-страница (см. Эту ссылку для домашней htmle-страницы - http://www.codeshare.io/arY9l6 см. Эту дыру html-страницу
<tbody>
{% if operations_form.errors %}
{{ operations_form.errors }}
{% endif %}
{{ operations_form.non_field_erros }}
{% for object in operations_form %}
{{ object.id }}
<tr id="formset">
<td class="m-ticker">{{ object.SizeType }}</td>
<td>{{ object.RequiredFabric }}</td>
<td></td>
</tr>
{% endfor %}
</tbody>
</table>
{{ operations_form.management_form }}