def form_valid(self, form):
self.object = form.save(commit=False)<EOL>self.pre_save()<EOL>self.object.save()<EOL>if hasattr(form, '<STR_LIT>'):<EOL><INDENT>form.save_m2m()<EOL><DEDENT>self.post_save()<EOL>if self.request.is_ajax():<EOL><INDENT>return self.render_json_response(self.get_success_result())<EOL><DEDENT>return HttpResponseRedirect(self.get_success_url())<EOL>
If the request is ajax, save the form and return a json response.
Otherwise return super as expected.