예제 #1
0
파일: views.py 프로젝트: arruda/rmr
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({})
예제 #2
0
파일: views.py 프로젝트: chennareddy/rmr
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({})
예제 #3
0
파일: views.py 프로젝트: chennareddy/rmr
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()
예제 #4
0
파일: views.py 프로젝트: arruda/rmr
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()