Add basic API module

This commit is contained in:
Kumi 2021-10-23 20:51:03 +02:00
parent 0d8c98c214
commit 8cbe5d5944
8 changed files with 31 additions and 0 deletions

0
api/__init__.py Normal file
View file

3
api/admin.py Normal file
View file

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

6
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'

3
api/models.py Normal file
View file

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

3
api/tests.py Normal file
View file

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

6
api/urls.py Normal file
View file

@ -0,0 +1,6 @@
from django.urls import path
from api.views import AvailabilityView
urlpatterns = [
path('availability/', AvailabilityView.as_view(), name="availability")
]

9
api/views.py Normal file
View file

@ -0,0 +1,9 @@
from django.views.generic import View
from django.http import JsonResponse
from buyer.models import Card
class AvailabilityView(View):
def get(self, request):
cards = len(Card.objects.filter(delivered__isnull=True))
return JsonResponse({"cards": cards})

View file

@ -19,5 +19,6 @@ from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/', include('django.contrib.auth.urls')),
path('api/', include('api.urls')),
path('', include('frontend.urls')),
]