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):
|
class CategoryForm(ModelForm):
|
||||||
|
template_name = "main/form.html"
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Category
|
model = Category
|
||||||
fields = ["name", "icon"]
|
fields = ["name", "icon"]
|
||||||
|
@ -47,6 +49,8 @@ class Transaction(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class TransactionForm(ModelForm):
|
class TransactionForm(ModelForm):
|
||||||
|
template_name = "main/form.html"
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Transaction
|
model = Transaction
|
||||||
fields = [
|
fields = [
|
||||||
|
@ -78,6 +82,8 @@ class Invoice(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class InvoiceForm(ModelForm):
|
class InvoiceForm(ModelForm):
|
||||||
|
template_name = "main/form.html"
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Invoice
|
model = Invoice
|
||||||
fields = ["name", "file"]
|
fields = ["name", "file"]
|
||||||
|
@ -178,6 +184,8 @@ class Snapshot(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class SnapshotForm(ModelForm):
|
class SnapshotForm(ModelForm):
|
||||||
|
template_name = "main/form.html"
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Snapshot
|
model = Snapshot
|
||||||
fields = ["date", "value"]
|
fields = ["date", "value"]
|
||||||
|
|
|
@ -13,11 +13,7 @@
|
||||||
|
|
||||||
<form action="{% url 'update_category' category.id %}" method="post">
|
<form action="{% url 'update_category' category.id %}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% for field in form %}
|
{{ form }}
|
||||||
{{ field.errors }}
|
|
||||||
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
|
|
||||||
{{ field }}
|
|
||||||
{% endfor %}
|
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<a href="{% url 'del_category' category.id %}"><input type="button" value="Delete" class="btn del" /></a>
|
<a href="{% url 'del_category' category.id %}"><input type="button" value="Delete" class="btn del" /></a>
|
||||||
<input type="reset" />
|
<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">
|
<form action="{% url 'update_snapshot' snapshot.id %}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% for field in form %}
|
{{ form }}
|
||||||
{{ field.errors }}
|
|
||||||
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
|
|
||||||
{{ field }}
|
|
||||||
{% endfor %}
|
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<a href="{% url 'del_snapshot' snapshot.date %}"><input type="button" value="Delete" class="del" /></a>
|
<a href="{% url 'del_snapshot' snapshot.date %}"><input type="button" value="Delete" class="del" /></a>
|
||||||
<input type="reset" />
|
<input type="reset" />
|
||||||
|
|
|
@ -12,11 +12,7 @@
|
||||||
{% spaceless %}
|
{% spaceless %}
|
||||||
<form id="transaction" action="{% url 'update_transaction' transaction.id %}" method="post">
|
<form id="transaction" action="{% url 'update_transaction' transaction.id %}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% for field in form %}
|
{{ form }}
|
||||||
{{ field.errors }}
|
|
||||||
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
|
|
||||||
{{ field }}
|
|
||||||
{% endfor %}
|
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<a href="{% url 'del_transaction' transaction.id %}"><input type="button" value="Delete" class="btn del" /></a>
|
<a href="{% url 'del_transaction' transaction.id %}"><input type="button" value="Delete" class="btn del" /></a>
|
||||||
<input class="btn" type="reset" />
|
<input class="btn" type="reset" />
|
||||||
|
@ -41,11 +37,7 @@
|
||||||
<h3>Add Invoice</h3>
|
<h3>Add Invoice</h3>
|
||||||
<form action="{% url 'add_invoice' transaction.id %}" method="post" enctype="multipart/form-data">
|
<form action="{% url 'add_invoice' transaction.id %}" method="post" enctype="multipart/form-data">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% for field in invoice_form %}
|
{{ invoice_form }}
|
||||||
{{ field.errors }}
|
|
||||||
<label for="{{ field.id_for_label }}">{{field.label }}</label>
|
|
||||||
{{ field }}
|
|
||||||
{% endfor %}
|
|
||||||
<div class="buttons"><input class="btn" type="submit" value="Add Invoice" /></div>
|
<div class="buttons"><input class="btn" type="submit" value="Add Invoice" /></div>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -163,8 +163,9 @@ def update_snapshot(request, uuid):
|
||||||
except Snapshot.DoesNotExist:
|
except Snapshot.DoesNotExist:
|
||||||
_snapshot = Snapshot(id=uuid)
|
_snapshot = Snapshot(id=uuid)
|
||||||
_form = SnapshotForm(request.POST, instance=_snapshot)
|
_form = SnapshotForm(request.POST, instance=_snapshot)
|
||||||
_form.save()
|
if _form.is_valid():
|
||||||
return redirect(snapshot, date=_snapshot.date)
|
_form.save()
|
||||||
|
return redirect(snapshot, date=_snapshot.date)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|
Loading…
Reference in a new issue