Skip to content

Commit 73c26f0

Browse files
bmispelonclaudep
authored andcommitted
Fixed #20270 -- Fixed error in AjaxResponseMixin documentation
1 parent 7cc3acb commit 73c26f0

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

docs/topics/class-based-views/generic-editing.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,24 @@ works for AJAX requests as well as 'normal' form POSTs::
237237
return HttpResponse(data, **response_kwargs)
238238

239239
def form_invalid(self, form):
240+
response = super(AjaxableResponseMixin, self).form_invalid(form)
240241
if self.request.is_ajax():
241242
return self.render_to_json_response(form.errors, status=400)
242243
else:
243-
return super(AjaxableResponseMixin, self).form_invalid(form)
244+
return response
244245

245246
def form_valid(self, form):
247+
# We make sure to call the parent's form_valid() method because
248+
# it might do some processing (in the case of CreateView, it will
249+
# call form.save() for example).
250+
response = super(AjaxableResponseMixin, self).form_valid(form)
246251
if self.request.is_ajax():
247252
data = {
248-
'pk': form.instance.pk,
253+
'pk': self.object.pk,
249254
}
250255
return self.render_to_json_response(data)
251256
else:
252-
return super(AjaxableResponseMixin, self).form_valid(form)
257+
return response
253258

254259
class AuthorCreate(AjaxableResponseMixin, CreateView):
255260
model = Author

0 commit comments

Comments
 (0)