Implemented frontend for category
This commit is contained in:
parent
719436f9ad
commit
f6e8b583cc
4 changed files with 19 additions and 17 deletions
|
@ -22,10 +22,10 @@ class Category(UserModel):
|
||||||
return str(self.name)
|
return str(self.name)
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse("category", kwargs={"pk": self.pk})
|
return reverse("category", args=(self.pk,))
|
||||||
|
|
||||||
def get_delete_url(self):
|
def get_delete_url(self):
|
||||||
return reverse("del_category", kwargs={"pk": self.pk})
|
return reverse("del_category", args=(self.pk,))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ["name"]
|
ordering = ["name"]
|
||||||
|
|
|
@ -9,9 +9,11 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block h2 %}{{ form.instance.icon|remix }}{{ form.instance }}{% endblock %}
|
{% block h2 %}{{ form.instance.icon|remix }}{{ form.instance }}{% endblock %}
|
||||||
{% block tables %}
|
{% block tables %}
|
||||||
{% if form.instance.transactions %}
|
{% if transactions %}
|
||||||
<h3>{% translate "Transactions" %}</h3>
|
<h3>{% translate "Transactions" %}</h3>
|
||||||
{% include "main/table/transaction.html" %}
|
{% include "main/table/transaction.html" %}
|
||||||
|
{% endif %}
|
||||||
|
{% if history.data %}
|
||||||
<h3>{% translate "History" %}</h3>
|
<h3>{% translate "History" %}</h3>
|
||||||
{% include "main/plot/history.html" %}
|
{% include "main/plot/history.html" %}
|
||||||
{% endif %}
|
{% endif %}
|
|
@ -4,18 +4,16 @@ from transaction.views import TransactionMonthView
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("category", views.CategoryCreateView.as_view(), name="new_category"),
|
path("", views.CategoryCreateView.as_view(), name="new_category"),
|
||||||
path("category/<pk>", views.CategoryUpdateView.as_view(), name="category"),
|
path("<category>", views.CategoryUpdateView.as_view(), name="category"),
|
||||||
path(
|
path(
|
||||||
"category/<pk>/transactions",
|
"<category>/transactions",
|
||||||
views.CategoryTListView.as_view(),
|
views.CategoryTListView.as_view(),
|
||||||
name="category_transactions",
|
name="category_transactions",
|
||||||
),
|
),
|
||||||
|
path("<category>/delete", views.CategoryDeleteView.as_view(), name="del_category"),
|
||||||
path(
|
path(
|
||||||
"category/<pk>/delete", views.CategoryDeleteView.as_view(), name="del_category"
|
"<category>/history/<int:year>/<int:month>",
|
||||||
),
|
|
||||||
path(
|
|
||||||
"category/<category>/history/<int:year>/<int:month>",
|
|
||||||
TransactionMonthView.as_view(),
|
TransactionMonthView.as_view(),
|
||||||
name="transaction_month",
|
name="transaction_month",
|
||||||
),
|
),
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from main.views import NummiCreateView, NummiDeleteView, NummiUpdateView
|
from main.views import NummiCreateView, NummiDeleteView, NummiUpdateView
|
||||||
from transaction.utils import history
|
from transaction.utils import history
|
||||||
|
@ -10,13 +11,12 @@ from .models import Category
|
||||||
class CategoryCreateView(NummiCreateView):
|
class CategoryCreateView(NummiCreateView):
|
||||||
model = Category
|
model = Category
|
||||||
form_class = CategoryForm
|
form_class = CategoryForm
|
||||||
template_name = "main/form/category.html"
|
|
||||||
|
|
||||||
|
|
||||||
class CategoryUpdateView(NummiUpdateView):
|
class CategoryUpdateView(NummiUpdateView):
|
||||||
model = Category
|
model = Category
|
||||||
form_class = CategoryForm
|
form_class = CategoryForm
|
||||||
template_name = "main/form/category.html"
|
pk_url_kwarg = "category"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
data = super().get_context_data(**kwargs)
|
data = super().get_context_data(**kwargs)
|
||||||
|
@ -33,17 +33,19 @@ class CategoryUpdateView(NummiUpdateView):
|
||||||
|
|
||||||
class CategoryDeleteView(NummiDeleteView):
|
class CategoryDeleteView(NummiDeleteView):
|
||||||
model = Category
|
model = Category
|
||||||
|
pk_url_kwarg = "category"
|
||||||
|
|
||||||
|
|
||||||
class CategoryMixin:
|
class CategoryMixin:
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return super().get_queryset().filter(category=self.kwargs.get("pk"))
|
self.category = get_object_or_404(
|
||||||
|
Category.objects.filter(user=self.request.user),
|
||||||
|
pk=self.kwargs.get("category"),
|
||||||
|
)
|
||||||
|
return super().get_queryset().filter(category=self.category)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
return super().get_context_data(**kwargs) | {
|
return super().get_context_data(**kwargs) | {"category": self.category}
|
||||||
"object": Category.objects.get(pk=self.kwargs.get("pk")),
|
|
||||||
"category": True,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class CategoryTListView(CategoryMixin, TransactionListView):
|
class CategoryTListView(CategoryMixin, TransactionListView):
|
||||||
|
|
Loading…
Reference in a new issue