Add backend for Add more checkbox

This commit is contained in:
Edgar P. Burkhart 2023-04-20 10:07:53 +02:00
parent 821d0d290a
commit 4a1d7778df
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
2 changed files with 25 additions and 3 deletions

View file

@ -53,6 +53,9 @@ class Account(NummiModel):
def __str__(self): def __str__(self):
return str(self.name) return str(self.name)
def get_create_url(self):
return reverse("account")
def get_absolute_url(self): def get_absolute_url(self):
return reverse("account", kwargs={"pk": self.pk}) return reverse("account", kwargs={"pk": self.pk})
@ -99,6 +102,9 @@ class Category(NummiModel):
def __str__(self): def __str__(self):
return str(self.name) return str(self.name)
def get_create_url(self):
return reverse("category")
def get_absolute_url(self): def get_absolute_url(self):
return reverse("category", kwargs={"pk": self.pk}) return reverse("category", kwargs={"pk": self.pk})
@ -183,6 +189,9 @@ class Snapshot(AccountModel):
self.file.delete() self.file.delete()
super().delete(*args, **kwargs) super().delete(*args, **kwargs)
def get_create_url(self):
return reverse("snapshot")
def get_absolute_url(self): def get_absolute_url(self):
return reverse("snapshot", kwargs={"pk": self.pk}) return reverse("snapshot", kwargs={"pk": self.pk})
@ -245,6 +254,9 @@ class Transaction(NummiModel):
def __str__(self): def __str__(self):
return f"{self.name}" return f"{self.name}"
def get_create_url(self):
return reverse("transaction")
def get_absolute_url(self): def get_absolute_url(self):
return reverse("transaction", kwargs={"pk": self.pk}) return reverse("transaction", kwargs={"pk": self.pk})
@ -294,6 +306,9 @@ class Invoice(NummiModel):
self.file.delete() self.file.delete()
super().delete(*args, **kwargs) super().delete(*args, **kwargs)
def get_create_url(self):
return reverse("invoice", kwargs={"transaction_pk": self.transaction.pk})
def get_absolute_url(self): def get_absolute_url(self):
return reverse( return reverse(
"invoice", kwargs={"transaction_pk": self.transaction.pk, "pk": self.pk} "invoice", kwargs={"transaction_pk": self.transaction.pk, "pk": self.pk}

View file

@ -9,7 +9,7 @@ from django.contrib.postgres.search import (
) )
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.db import models 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.shortcuts import get_object_or_404, redirect
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.views import View from django.views import View
@ -73,11 +73,18 @@ class UserFormMixin:
class NummiCreateView(UserMixin, UserFormMixin, CreateView): class NummiCreateView(UserMixin, UserFormMixin, CreateView):
def form_valid(self, form): def form_valid(self, form):
form.instance.user = self.request.user 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): 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): class NummiDeleteView(UserMixin, DeleteView):