Use form template
This commit is contained in:
parent
c5ac2d83c7
commit
11c215e4d8
6 changed files with 20 additions and 22 deletions
|
@ -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"]
|
||||
|
|
|
@ -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" />
|
||||
|
|
5
nummi/main/templates/main/form.html
Normal file
5
nummi/main/templates/main/form.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
{% for field in form %}
|
||||
{{ field.errors }}
|
||||
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
|
||||
{{ field }}
|
||||
{% endfor %}
|
|
@ -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" />
|
||||
|
|
|
@ -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 %}
|
||||
|
|
|
@ -163,6 +163,7 @@ def update_snapshot(request, uuid):
|
|||
except Snapshot.DoesNotExist:
|
||||
_snapshot = Snapshot(id=uuid)
|
||||
_form = SnapshotForm(request.POST, instance=_snapshot)
|
||||
if _form.is_valid():
|
||||
_form.save()
|
||||
return redirect(snapshot, date=_snapshot.date)
|
||||
|
||||
|
|
Loading…
Reference in a new issue