Add snapshot form
This commit is contained in:
parent
4b784a553b
commit
cb458cf472
17 changed files with 159 additions and 372 deletions
|
@ -11,6 +11,7 @@ from .models import (
|
|||
Category,
|
||||
CategoryForm,
|
||||
Snapshot,
|
||||
SnapshotForm,
|
||||
)
|
||||
|
||||
|
||||
|
@ -59,10 +60,7 @@ def transaction(request, uuid=None):
|
|||
|
||||
@login_required
|
||||
def update_transaction(request, uuid):
|
||||
try:
|
||||
_transaction = Transaction.objects.get(id=uuid)
|
||||
except Transaction.DoesNotExist:
|
||||
_transaction = Transaction(id=uuid)
|
||||
_transaction, _ = Transaction.objects.get_or_create(id=uuid)
|
||||
_form = TransactionForm(request.POST, instance=_transaction)
|
||||
_form.save()
|
||||
return redirect(transaction, uuid=uuid)
|
||||
|
@ -112,10 +110,38 @@ def category(request, uuid=None):
|
|||
|
||||
@login_required
|
||||
def update_category(request, uuid):
|
||||
try:
|
||||
_category = Category.objects.get(id=uuid)
|
||||
except Category.DoesNotExist:
|
||||
_category = Category(id=uuid)
|
||||
_category, _ = Category.objects.get_or_create(id=uuid)
|
||||
_form = CategoryForm(request.POST, instance=_category)
|
||||
_form.save()
|
||||
return redirect(category, uuid=uuid)
|
||||
|
||||
|
||||
@login_required
|
||||
def snapshot(request, date=None):
|
||||
if date is None:
|
||||
_snapshot = Snapshot()
|
||||
else:
|
||||
_snapshot = get_object_or_404(Snapshot, date=date)
|
||||
return render(
|
||||
request,
|
||||
"main/snapshot.html",
|
||||
{
|
||||
"snapshot": _snapshot,
|
||||
"form": SnapshotForm(instance=_snapshot),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def update_snapshot(request, uuid):
|
||||
_snapshot, _ = Snapshot.objects.get_or_create(id=uuid)
|
||||
_form = SnapshotForm(request.POST, instance=_snapshot)
|
||||
_form.save()
|
||||
return redirect(snapshot, date=_snapshot.date)
|
||||
|
||||
|
||||
@login_required
|
||||
def del_snapshot(request, date):
|
||||
_snapshot = get_object_or_404(Snapshot, date=date)
|
||||
_snapshot.delete()
|
||||
return redirect(index)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue