﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20270	bug in ajax example	tejinderss@…	nobody	"https://docs.djangoproject.com/en/dev/topics/class-based-views/generic-editing/#ajax-example

This example does not work with CreateView or UpdateView because the form_valid overriding never saves the form and neither does it call its super class which does. So in order for CreateView to create new object, we would either have to add:

    def form_valid(self, form):
        if self.request.is_ajax():
            '''self.object = form.save()'''
            data = {
                'pk': form.instance.pk,
            }
            return self.render_to_json_response(data)
        else:
            return super(AjaxableResponseMixin, self).form_valid(form)

Or somehow call the super form_valid and then return the HttpResponse."	Bug	closed	Documentation	dev	Normal	fixed		bmispelon@…	Accepted	1	0	0	0	1	0
