diff --git a/nummi/main/models.py b/nummi/main/models.py index f635fbe..b1662d6 100644 --- a/nummi/main/models.py +++ b/nummi/main/models.py @@ -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"] diff --git a/nummi/main/templates/main/category.html b/nummi/main/templates/main/category.html index 851ae6c..ec1c51c 100644 --- a/nummi/main/templates/main/category.html +++ b/nummi/main/templates/main/category.html @@ -13,11 +13,7 @@
{% csrf_token %} - {% for field in form %} - {{ field.errors }} - - {{ field }} - {% endfor %} + {{ form }}
diff --git a/nummi/main/templates/main/form.html b/nummi/main/templates/main/form.html new file mode 100644 index 0000000..8268316 --- /dev/null +++ b/nummi/main/templates/main/form.html @@ -0,0 +1,5 @@ + {% for field in form %} + {{ field.errors }} + + {{ field }} + {% endfor %} diff --git a/nummi/main/templates/main/snapshot.html b/nummi/main/templates/main/snapshot.html index 7621383..72d7993 100644 --- a/nummi/main/templates/main/snapshot.html +++ b/nummi/main/templates/main/snapshot.html @@ -23,11 +23,7 @@ {% csrf_token %} - {% for field in form %} - {{ field.errors }} - - {{ field }} - {% endfor %} + {{ form }}
diff --git a/nummi/main/templates/main/transaction.html b/nummi/main/templates/main/transaction.html index 24dfde0..f0b4deb 100644 --- a/nummi/main/templates/main/transaction.html +++ b/nummi/main/templates/main/transaction.html @@ -12,11 +12,7 @@ {% spaceless %} {% csrf_token %} - {% for field in form %} - {{ field.errors }} - - {{ field }} - {% endfor %} + {{ form }}
@@ -41,11 +37,7 @@

Add Invoice

{% csrf_token %} - {% for field in invoice_form %} - {{ field.errors }} - - {{ field }} - {% endfor %} + {{ invoice_form }}
{% endblock %} diff --git a/nummi/main/views.py b/nummi/main/views.py index 9c11ea6..59c572b 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -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