Use form template

This commit is contained in:
Edgar P. Burkhart 2022-05-22 18:14:11 +02:00
parent c5ac2d83c7
commit 11c215e4d8
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
6 changed files with 20 additions and 22 deletions

View file

@ -18,6 +18,8 @@ class Category(models.Model):
class CategoryForm(ModelForm):
template_name = "main/form.html"
class Meta:
model = Category
fields = ["name", "icon"]
@ -47,6 +49,8 @@ class Transaction(models.Model):
class TransactionForm(ModelForm):
template_name = "main/form.html"
class Meta:
model = Transaction
fields = [
@ -78,6 +82,8 @@ class Invoice(models.Model):
class InvoiceForm(ModelForm):
template_name = "main/form.html"
class Meta:
model = Invoice
fields = ["name", "file"]
@ -178,6 +184,8 @@ class Snapshot(models.Model):
class SnapshotForm(ModelForm):
template_name = "main/form.html"
class Meta:
model = Snapshot
fields = ["date", "value"]

View file

@ -13,11 +13,7 @@
<form action="{% url 'update_category' category.id %}" method="post">
{% csrf_token %}
{% for field in form %}
{{ field.errors }}
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
{{ field }}
{% endfor %}
{{ form }}
<div class="buttons">
<a href="{% url 'del_category' category.id %}"><input type="button" value="Delete" class="btn del" /></a>
<input type="reset" />

View file

@ -0,0 +1,5 @@
{% for field in form %}
{{ field.errors }}
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
{{ field }}
{% endfor %}

View file

@ -23,11 +23,7 @@
<form action="{% url 'update_snapshot' snapshot.id %}" method="post">
{% csrf_token %}
{% for field in form %}
{{ field.errors }}
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
{{ field }}
{% endfor %}
{{ form }}
<div class="buttons">
<a href="{% url 'del_snapshot' snapshot.date %}"><input type="button" value="Delete" class="del" /></a>
<input type="reset" />

View file

@ -12,11 +12,7 @@
{% spaceless %}
<form id="transaction" action="{% url 'update_transaction' transaction.id %}" method="post">
{% csrf_token %}
{% for field in form %}
{{ field.errors }}
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
{{ field }}
{% endfor %}
{{ form }}
<div class="buttons">
<a href="{% url 'del_transaction' transaction.id %}"><input type="button" value="Delete" class="btn del" /></a>
<input class="btn" type="reset" />
@ -41,11 +37,7 @@
<h3>Add Invoice</h3>
<form action="{% url 'add_invoice' transaction.id %}" method="post" enctype="multipart/form-data">
{% csrf_token %}
{% for field in invoice_form %}
{{ field.errors }}
<label for="{{ field.id_for_label }}">{{field.label }}</label>
{{ field }}
{% endfor %}
{{ invoice_form }}
<div class="buttons"><input class="btn" type="submit" value="Add Invoice" /></div>
</form>
{% endblock %}

View file

@ -163,8 +163,9 @@ def update_snapshot(request, uuid):
except Snapshot.DoesNotExist:
_snapshot = Snapshot(id=uuid)
_form = SnapshotForm(request.POST, instance=_snapshot)
_form.save()
return redirect(snapshot, date=_snapshot.date)
if _form.is_valid():
_form.save()
return redirect(snapshot, date=_snapshot.date)
@login_required