Ejemplo n.º 1
0
def create_expense(request):
    if request.method == 'GET':
        context = {
            'form': ExpenseForm(),
        }

        return render(request, 'expense-create.html', context)
    else:
        form = ExpenseForm(request.POST)
        if form.is_valid():
            expense = form.save(commit=False)
            expense.profile = get_profile()
            expense.save()
            return redirect('index')

        context = {
            'form': form,
        }

        return render(request, 'expense-create.html', context)
Ejemplo n.º 2
0
def create_expense(request):
    if request.method == "GET":
        context = {"form": ExpenseForm()}
        return render(request, "expense-create.html", context)
    else:
        form = ExpenseForm(request.POST)

        if form.is_valid():
            form.save()
            return redirect("index")

        context = {"form": form}
        return render(request, "expense-create.html", context)
def create_expense_page(request):
    if request.method == 'GET':
        context = {
            'form': ExpenseForm(),
        }
        return render(request, 'expense-create.html', context)
    else:
        form = ExpenseForm(request.POST)  # when click submit button
        if form.is_valid():
            form.save()
            return redirect('home page')
        # else:
        context = {
            'form': form,
        }
        return render(request, 'expense-create.html', context)
Ejemplo n.º 4
0
def create_expense(request):
    if request.method == 'GET':
        context = {
            'form': ExpenseForm(),
        }
        return render(request, 'expense-create.html', context)
    else:
        form = ExpenseForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('index')

        context = {
            'form': form
        }
        return render(request, 'expense-create.html', context)
Ejemplo n.º 5
0
def edit_expense(request, pk):
    expense = Expense.objects.get(pk=pk)
    if request.method == 'GET':
        context = {
            'expense': expense,
            'form': ExpenseForm(instance=expense),
        }
        return render(request, 'expense-edit.html', context)
    else:
        form = ExpenseForm(request.POST, instance=expense)
        if form.is_valid():
            form.save()
            return redirect('index')
        context = {
            'expense': expense,
            'form': form,
        }
        return render(request, 'expense-edit.html', context)
Ejemplo n.º 6
0
def edit_expense(request, pk):
    expense = Expenses.objects.get(pk=pk)
    if request.method == "GET":
        context = {
            "expense": expense,
            "form": ExpenseForm(instance=expense),
        }
        return render(request, "expense-edit.html", context)
    else:
        form = ExpenseForm(request.POST, instance=expense)

        if form.is_valid():
            form.save()
            return redirect("index")

        context = {
            "expense": expense,
            "form": form,
        }
        return render(request, "expense-edit.html", context)