From 6bb8df0a982bb394f2cf33cfc9d9d71589515801 Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Mon, 22 Apr 2013 19:04:28 +0200 Subject: [PATCH] [1.5.x] Fixed #20270 -- Fixed error in AjaxResponseMixin documentation Backport of 73c26f0c95 from master. --- docs/topics/class-based-views/generic-editing.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/topics/class-based-views/generic-editing.txt b/docs/topics/class-based-views/generic-editing.txt index 8cd34f8ad95..66ba36fd873 100644 --- a/docs/topics/class-based-views/generic-editing.txt +++ b/docs/topics/class-based-views/generic-editing.txt @@ -237,19 +237,24 @@ works for AJAX requests as well as 'normal' form POSTs:: return HttpResponse(data, **response_kwargs) def form_invalid(self, form): + response = super(AjaxableResponseMixin, self).form_invalid(form) if self.request.is_ajax(): return self.render_to_json_response(form.errors, status=400) else: - return super(AjaxableResponseMixin, self).form_invalid(form) + return response def form_valid(self, form): + # We make sure to call the parent's form_valid() method because + # it might do some processing (in the case of CreateView, it will + # call form.save() for example). + response = super(AjaxableResponseMixin, self).form_valid(form) if self.request.is_ajax(): data = { - 'pk': form.instance.pk, + 'pk': self.object.pk, } return self.render_to_json_response(data) else: - return super(AjaxableResponseMixin, self).form_valid(form) + return response class AuthorCreate(AjaxableResponseMixin, CreateView): model = Author