def new_ajax(request): "create a new author for the logged user, using ajax" if request.method == 'POST': post_dict = request.POST.copy() post_dict['user'] = request.user.id form = NewAuthorForm(post_dict) if form.is_valid(): author = form.save() return JsonResponse({'model':"author",'id':author.id, 'name':author.name}) else: return JsonResponse({'errors': form.errors}) return JsonResponse({})
def new_ajax(request): "create a new author for the logged user, using ajax" if request.method == 'POST': post_dict = request.POST.copy() post_dict['user'] = request.user.id form = NewAuthorForm(post_dict) if form.is_valid(): author = form.save() return JsonResponse({ 'model': "author", 'id': author.id, 'name': author.name }) else: return JsonResponse({'errors': form.errors}) return JsonResponse({})
def new(request): "create a new author for the logged user" if request.method == 'POST': form = NewAuthorForm(request.POST) if form.is_valid(): author = form.save(commit=False) author.user = request.user author.save() form.save_m2m() return redirect('filter_books') else: form = NewAuthorForm() return locals()