Add basic API module
This commit is contained in:
parent
0d8c98c214
commit
8cbe5d5944
8 changed files with 31 additions and 0 deletions
0
api/__init__.py
Normal file
0
api/__init__.py
Normal file
3
api/admin.py
Normal file
3
api/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
6
api/apps.py
Normal file
6
api/apps.py
Normal 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
3
api/models.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
3
api/tests.py
Normal file
3
api/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
6
api/urls.py
Normal file
6
api/urls.py
Normal 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
9
api/views.py
Normal 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})
|
|
@ -19,5 +19,6 @@ from django.urls import include, path
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('accounts/', include('django.contrib.auth.urls')),
|
path('accounts/', include('django.contrib.auth.urls')),
|
||||||
|
path('api/', include('api.urls')),
|
||||||
path('', include('frontend.urls')),
|
path('', include('frontend.urls')),
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue