コード例 #1
0
ファイル: views.py プロジェクト: wanshot/trdist
def add(request):
    if not is_company_staff(request):
        return redirect('mypage_home')
    user = request.user
    company = user.customer_company
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            document = form.save(commit=False)
            document.user = user
            document.company = company
            document.save()
            form.save_m2m()
            messages.add_message(request, messages.SUCCESS, '資料を保存しました')
            return redirect('document_edit', document_id=document.pk)
    else:
        form = DocumentForm()

    return render_to_response(
        'documents/add_edit.html',
        {
            'action': 'add',
            'form': form,
        },
        context_instance=RequestContext(request)
    )
コード例 #2
0
def add(request):
    if not is_company_staff(request):
        return redirect('mypage_home')
    user = request.user
    company = user.customer_company
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            document = form.save(commit=False)
            document.user = user
            document.company = company
            document.save()
            form.save_m2m()
            messages.add_message(request, messages.SUCCESS, '資料を保存しました')
            return redirect('document_edit', document_id=document.pk)
    else:
        form = DocumentForm()

    return render_to_response('documents/add_edit.html', {
        'action': 'add',
        'form': form,
    },
                              context_instance=RequestContext(request))