diff --git a/nummi/main/models.py b/nummi/main/models.py index d967eda..1d77de0 100644 --- a/nummi/main/models.py +++ b/nummi/main/models.py @@ -53,6 +53,9 @@ class Account(NummiModel): def __str__(self): return str(self.name) + def get_create_url(self): + return reverse("account") + def get_absolute_url(self): return reverse("account", kwargs={"pk": self.pk}) @@ -99,6 +102,9 @@ class Category(NummiModel): def __str__(self): return str(self.name) + def get_create_url(self): + return reverse("category") + def get_absolute_url(self): return reverse("category", kwargs={"pk": self.pk}) @@ -183,6 +189,9 @@ class Snapshot(AccountModel): self.file.delete() super().delete(*args, **kwargs) + def get_create_url(self): + return reverse("snapshot") + def get_absolute_url(self): return reverse("snapshot", kwargs={"pk": self.pk}) @@ -245,6 +254,9 @@ class Transaction(NummiModel): def __str__(self): return f"{self.name}" + def get_create_url(self): + return reverse("transaction") + def get_absolute_url(self): return reverse("transaction", kwargs={"pk": self.pk}) @@ -294,6 +306,9 @@ class Invoice(NummiModel): self.file.delete() super().delete(*args, **kwargs) + def get_create_url(self): + return reverse("invoice", kwargs={"transaction_pk": self.transaction.pk}) + def get_absolute_url(self): return reverse( "invoice", kwargs={"transaction_pk": self.transaction.pk, "pk": self.pk} diff --git a/nummi/main/views.py b/nummi/main/views.py index 40f5276..3fc87d9 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -9,7 +9,7 @@ from django.contrib.postgres.search import ( ) from django.core.exceptions import PermissionDenied from django.db import models -from django.http import HttpResponse +from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import get_object_or_404, redirect from django.urls import reverse_lazy from django.views import View @@ -73,11 +73,18 @@ class UserFormMixin: class NummiCreateView(UserMixin, UserFormMixin, CreateView): def form_valid(self, form): form.instance.user = self.request.user - return super().form_valid(form) + _res = super().form_valid(form) + if form.data["addmore"]: + return HttpResponseRedirect(self.object.get_create_url()) + return _res class NummiUpdateView(UserMixin, UserFormMixin, UpdateView): - pass + def form_valid(self, form): + _res = super().form_valid(form) + if form.data["addmore"]: + return HttpResponseRedirect(self.object.get_create_url()) + return _res class NummiDeleteView(UserMixin, DeleteView):