Remove get_create_url, redirect createform to same page using hidden form field
This commit is contained in:
parent
c744c87baa
commit
600a79c3b7
4 changed files with 6 additions and 19 deletions
|
@ -53,9 +53,6 @@ class Account(NummiModel):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.name)
|
return str(self.name)
|
||||||
|
|
||||||
def get_create_url(self):
|
|
||||||
return reverse("new_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})
|
||||||
|
|
||||||
|
@ -102,9 +99,6 @@ class Category(NummiModel):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.name)
|
return str(self.name)
|
||||||
|
|
||||||
def get_create_url(self):
|
|
||||||
return reverse("new_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})
|
||||||
|
|
||||||
|
@ -189,9 +183,6 @@ class Snapshot(AccountModel):
|
||||||
self.file.delete()
|
self.file.delete()
|
||||||
super().delete(*args, **kwargs)
|
super().delete(*args, **kwargs)
|
||||||
|
|
||||||
def get_create_url(self):
|
|
||||||
return reverse("new_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})
|
||||||
|
|
||||||
|
@ -254,9 +245,6 @@ class Transaction(NummiModel):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.name}"
|
return f"{self.name}"
|
||||||
|
|
||||||
def get_create_url(self):
|
|
||||||
return reverse("new_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})
|
||||||
|
|
||||||
|
@ -306,9 +294,6 @@ class Invoice(NummiModel):
|
||||||
self.file.delete()
|
self.file.delete()
|
||||||
super().delete(*args, **kwargs)
|
super().delete(*args, **kwargs)
|
||||||
|
|
||||||
def get_create_url(self):
|
|
||||||
return reverse("new_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}
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<form method="post">
|
<form method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
{% if instance.adding %}<input hidden name="next" value="{{ request.path }}" />{% endif %}
|
||||||
{{ form }}
|
{{ form }}
|
||||||
</form>
|
</form>
|
||||||
{% block tables %}{% endblock %}
|
{% block tables %}{% endblock %}
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="3">
|
<td colspan="3">
|
||||||
<a href="{% url "invoice" transaction.pk %}">{% translate "New invoice" %}</a>
|
<a href="{% url "new_invoice" transaction.pk %}">{% translate "New invoice" %}</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
|
|
|
@ -71,13 +71,14 @@ class UserFormMixin:
|
||||||
|
|
||||||
|
|
||||||
class NummiCreateView(UserMixin, UserFormMixin, CreateView):
|
class NummiCreateView(UserMixin, UserFormMixin, CreateView):
|
||||||
def get_success_url(self):
|
|
||||||
return self.object.get_create_url()
|
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
form.instance.user = self.request.user
|
form.instance.user = self.request.user
|
||||||
|
self.next = form.data.get("next", None)
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
return self.next or super().get_success_url()
|
||||||
|
|
||||||
|
|
||||||
class NummiUpdateView(UserMixin, UserFormMixin, UpdateView):
|
class NummiUpdateView(UserMixin, UserFormMixin, UpdateView):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in a new issue