Есть вьюха использующая modelformset. Если заполнены все видимые формы, то все отрабатывает как надо. Если хотя бы одна из форм пустая то получаю ошибку
The view base.views.SkillTestCreateView didn't return an HttpResponse object. It returned None instead.
views.pyclass SkillTestCreateView(AuthorizedMixin, CreateView):
model = Skill
form_class = SkillCreateForm
template_name = 'skill_create.html'
def get_context_data(self, **kwargs):
context = super(SkillTestCreateView, self).get_context_data(**kwargs)
employee_current_technology = Technology.objects.filter(skill__employee__id=self.kwargs['pk'])
context['formset_framework'] = SkillFrameworkFormSet()
context['formset_planguage'] = SkillPLanguageFormSet()
context['tech_group'] = Techgroup.objects.all()
return context
def post(self, request, *args, **kwargs):
if 'framework' in request.POST:
form = SkillFrameworkFormSet(self.request.POST)
if form.is_valid():
return self.form_valid(form)
elif 'language' in request.POST:
form = SkillPLanguageFormSet(self.request.POST)
if form.is_valid():
return self.form_valid(form)
else:
return self.form_invalid(self.form)
def form_valid(self, form):
"""If the form is valid, redirect to the supplied URL."""
for form in form:
self.object = form.save(commit=False)
self.object.employee =Employee.objects.get(pk=self.kwargs['pk'])
self.object.save()
return redirect("profile", pk=self.kwargs['pk'])
def form_invalid(self, formset_framework, formset_planguage):
return self.render_to_response(self.get_context_data(formset_framework=self.formset_framework,
formset_planguage=self.formset_planguage))
Как изменить код, чтобы была возможность отправлять пустые формы?