Try this code. Instead of using kwargs[], context is most common.

class SkladCreateView(LoginRequiredMixin, CustomSuccessMessageMixin, 
CreateView):
 model = Sklad
 template_name = 'sklad.html'
 form_class = SkladForm
 success_url = reverse_lazy('sklad')
 success_msg = 'Материал сохранён'

 def get_context_data(self, **kwargs):
  #kwargs['sklad_form'] = SkladForm # you do not need this anymore since 
you have set the form_class above.
  context = super(SkladCreateView, self).get_context_data(**kwargs)
  if self.request.POST:
   context['pack_form'] = PackForm(self.request.POST)
  else:
   context['pack_form'] = PackForm()
  return super().get_context_data(**kwargs)
 
 def form_valid(self, form):
  self.object = form.save(commit=False)
  self.object.author = self.request.user
  self.object.save()
  context = self.get_context_data()
  pack_form = context['pack_form']
  if pack_form.is_valid():
   pack_form.instance = self.object
   pack_form.save()
  return super().form_valid(form)






-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d0caa200-3dc7-489e-a8b4-fa5c728d1c59%40googlegroups.com.

Reply via email to