why django inlineformset_factory not saving the froms data?

Why inlineformset_factory froms data not saving ? field is rendering in my html template but froms data not saving. here is my code:


class HeaderImage(models.Model):
      header_image = models.ImageField()
      post = models.ForeignKey(Post, on_delete=models.CASCADE)


BlogImageFormSet = inlineformset_factory(Post,  # parent form
                                                  HeaderImage,  # inline-form

                                                fields=['header_image'] ,can_delete=False, extra=1)


class BlogUpdateView(PermissionRequiredMixin,UpdateView):
      raise_exception = True
      permission_required = "blog.change_post"
      model = Post
      template_name = "blog_update_post.html"
      form_class = BlogPost

      def get_success_url(self):
        self.success_url = reverse_lazy('my-account')
        return self.success_url
      def get_context_data(self, **kwargs):
        context = super(BlogUpdateView, self).get_context_data(**kwargs)
        if self.request.POST:
            context['form_image'] = BlogImageFormSet(self.request.POST, instance=self.object)
            context['form_image'] = BlogImageFormSet(instance=self.object)
        return context

      def form_valid(self, form):
            context = self.get_context_data()
            image_form = context['form_image']

            if  image_form.is_valid():
                  self.object = form.save()
                  image_form.instance = self.object
                  return HttpResponseRedirect(self.get_success_url())
                  return self.render_to_response(self.get_context_data(form=form))

I am not understanding why data is not saving for inlineformset_factory field.

What errors or responses are you getting from the submit? If you’re not getting any tracebacks, what error messages are being returned to the form? (Are you displaying error messages in your form? If not, it would be worth printing any existing error messages before you exit the form_valid function.)

Thanks KenWhitesell for your replay. I am not getting any error. Others models fields data saving except fields of inlineformset_factory. see the picture

I am not understanding why data of inlineformset_factory not saving.


I was reviewing your topic regarding inline formset, and I’m having an issue saving my data as well

If you are interested in getting assistance with your issue, I would suggest you open a new topic, posting all the relevant information.
That would include a complete description of what’s happening, along with all the code involved - models, views, and templates.
When posting code, post the actual code in the message - no screenshots. Enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then the code, then another line of ```. (You can do that multiple times in one post - you could have some text, a line of ```, some code, another line of ```, more text, etc)

1 Like