Add snapshot, account and category endpoints
This commit is contained in:
parent
887d2074dc
commit
cba2358c0b
2 changed files with 26 additions and 2 deletions
|
@ -3,5 +3,8 @@ from django.urls import path
|
|||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("transactions", views.TransactionListView.as_view(), name="index"),
|
||||
path("transactions", views.TransactionListView.as_view(), name="transactions"),
|
||||
path("categories", views.CategoryListView.as_view(), name="categories"),
|
||||
path("accounts", views.AccountListView.as_view(), name="accounts"),
|
||||
path("snapshots", views.SnapshotListView.as_view(), name="snapshots"),
|
||||
]
|
||||
|
|
|
@ -2,7 +2,7 @@ from django.http import JsonResponse
|
|||
from django.views import View
|
||||
from django.views.generic.list import MultipleObjectMixin
|
||||
|
||||
from main.models import Transaction
|
||||
from main.models import Account, Category, Snapshot, Transaction
|
||||
from main.views import UserMixin
|
||||
|
||||
|
||||
|
@ -11,3 +11,24 @@ class TransactionListView(UserMixin, MultipleObjectMixin, View):
|
|||
|
||||
def get(self, request, *args, **kwargs):
|
||||
return JsonResponse({"transactions": list(self.get_queryset().values())})
|
||||
|
||||
|
||||
class CategoryListView(UserMixin, MultipleObjectMixin, View):
|
||||
model = Category
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
return JsonResponse({"categories": list(self.get_queryset().values())})
|
||||
|
||||
|
||||
class AccountListView(UserMixin, MultipleObjectMixin, View):
|
||||
model = Account
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
return JsonResponse({"accounts": list(self.get_queryset().values())})
|
||||
|
||||
|
||||
class SnapshotListView(UserMixin, MultipleObjectMixin, View):
|
||||
model = Snapshot
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
return JsonResponse({"snapshots": list(self.get_queryset().values())})
|
||||
|
|
Loading…
Reference in a new issue