Replaced the get_absolute_url() method in the transaction data model with the get_success_url() method in the transaction form model, and added the current application to the arguments to enable multiple instances of the application in the accounting application.

This commit is contained in:
依瑪貓 2020-08-17 22:23:30 +08:00
parent 5898a48fe9
commit 64769440a7
2 changed files with 6 additions and 12 deletions

View File

@ -160,18 +160,6 @@ class Transaction(DirtyFieldsMixin, models.Model):
transaction."""
return self.date.__str__() + " #" + self.ord.__str__()
def get_absolute_url(self) -> str:
"""Returns the URL to view this transaction."""
if self.is_cash_expense:
return reverse(
"accounting:transactions.detail", args=("expense", self))
elif self.is_cash_income:
return reverse(
"accounting:transactions.detail", args=("income", self))
else:
return reverse(
"accounting:transactions.detail", args=("transfer", self))
def is_dirty(self, check_relationship=False, check_m2m=None) -> bool:
"""Returns whether the data of this transaction is changed and need
to be saved into the database.

View File

@ -860,6 +860,12 @@ class TransactionFormView(FormView):
"""Returns the current object, or None on a create form."""
return self.kwargs.get("txn")
def get_success_url(self) -> str:
"""Returns the URL on success."""
return reverse("accounting:transactions.detail",
args=(self.txn_type, self.get_object()),
current_app=self.request.resolver_match.namespace)
@property
def txn_type(self) -> str:
"""Returns the transaction type of this form."""