Beispiel #1
0
def add(request):
    form = OfficeForm()
    if request.method == 'POST':
        form = OfficeForm(request.POST, request.FILES)
        if form.is_valid:
            new_office = form.save(commit=False)
            new_office.created_by = request.user
            new_office.save()
            return HttpResponseRedirect('/offices/view/%s/' % new_office.id)
    return render_to_response('offices/add.html', {
        'form': form,
    }, context_instance=RequestContext(request))
Beispiel #2
0
def company_new(request):
    if request.method == 'POST':
        form = CompanyForm(request.POST)

        if form.is_valid():
            company = form.save(commit=False)
            company.save()
            form.save_m2m()

            # Auto-create a default office
            office_form = OfficeForm()
            office = office_form.save(commit=False)
            office.company_id = company.id
            office.name = 'Default'
            office.save()

            context = {'company': company}

            return render(request, 'companies/company_view.html', context)
    else:
        form = CompanyForm()

    return render(request, 'companies/company_edit.html', {'form': form})
def company_new(request):
    if request.method == 'POST':
        form = CompanyForm(request.POST)

        if form.is_valid():
            company = form.save(commit=False)
            company.save()
            form.save_m2m()

            # Auto-create a default office
            office_form = OfficeForm()
            office = office_form.save(commit=False)
            office.company_id = company.id
            office.name = 'Default'
            office.save()

            context = {'company': company}

            return render(request, 'companies/company_view.html', context)
    else:
        form = CompanyForm()

    return render(request, 'companies/company_edit.html', {'form': form})