All transactions endpoint

This commit is contained in:
Edgar P. Burkhart 2023-04-14 15:33:43 +02:00
parent 60c875c2a5
commit 887d2074dc
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
9 changed files with 36 additions and 0 deletions

0
nummi/api/__init__.py Normal file
View file

3
nummi/api/admin.py Normal file
View file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
nummi/api/apps.py Normal file
View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class ApiConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "api"

View file

3
nummi/api/models.py Normal file
View file

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
nummi/api/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

7
nummi/api/urls.py Normal file
View file

@ -0,0 +1,7 @@
from django.urls import path
from . import views
urlpatterns = [
path("transactions", views.TransactionListView.as_view(), name="index"),
]

13
nummi/api/views.py Normal file
View file

@ -0,0 +1,13 @@
from django.http import JsonResponse
from django.views import View
from django.views.generic.list import MultipleObjectMixin
from main.models import Transaction
from main.views import UserMixin
class TransactionListView(UserMixin, MultipleObjectMixin, View):
model = Transaction
def get(self, request, *args, **kwargs):
return JsonResponse({"transactions": list(self.get_queryset().values())})

View file

@ -20,6 +20,7 @@ from django.urls import include, path
urlpatterns = i18n_patterns( urlpatterns = i18n_patterns(
path("", include("main.urls")), path("", include("main.urls")),
path("plot/", include("plot.urls")), path("plot/", include("plot.urls")),
path("api/", include("api.urls")),
path("admin/", admin.site.urls), path("admin/", admin.site.urls),
prefix_default_language=False, prefix_default_language=False,
) )