feat: first version of rest api using viewsets

parent f1d86cc5
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class ApiConfig(AppConfig):
name = 'api'
from django.db import models
# Create your models here.
# contrib
from rest_framework import serializers
# project
from apps.map import models
class TestimonySerializer(serializers.ModelSerializer):
position = serializers.JSONField()
class Meta:
model = models.Testimony
fields = (
'position',
'summary',
'name',
'link',
'image',
)
from django.test import TestCase
# Create your tests here.
# django
from django.urls import path, include
# contrib
from rest_framework import routers
# app
from . import views
router = routers.DefaultRouter()
router.register(r'testimonies', views.TestimonyViewSet)
urlpatterns = [
# Tracks
path(
'',
include(router.urls)
),
]
# python
#import json
#
# django
#from django.http import HttpResponse, JsonResponse
from rest_framework import viewsets
# project
from apps.map import models
from .serializers import TestimonySerializer
#def testimonies(request):
# testimonies = Testimony.objects.all().order_by('name');
# if testimonies:
# data = TestimonySerializer(testimonies, many=True).data
# return JsonResponse(
# data,
# safe=False,
# status=200,
# )
# return JsonReponse(
# [],
# safe=False,
# status=200,
# )
# return HttpResponse(status=403)
class TestimonyViewSet(viewsets.ModelViewSet):
queryset = models.Testimony.objects.all().order_by('name')
serializer_class = TestimonySerializer
......@@ -41,12 +41,14 @@ CONTRIB_APPS = [
'ckeditor_uploader',
'imagekit',
'adminsortable',
'rest_framework',
]
PROJECT_APPS = [
'apps.model_utils',
'apps.map',
'apps.connectors'
'apps.connectors',
'apps.api'
]
INSTALLED_APPS = PROJECT_ADMIN_APPS + DJANGO_APPS + CONTRIB_APPS + PROJECT_APPS
......
......@@ -7,6 +7,7 @@ from django.conf.urls.static import static
# project
from django.conf import settings
from apps.connectors import urls as webhooks
from apps.api import urls as api
urlpatterns = [
# admin
......@@ -35,7 +36,16 @@ urlpatterns = [
webhooks,
namespace="webhooks"
)
)
),
# API
# v1.0
path(
'api/1.0/',
include(
api,
)
),
]
# Add static URLS when running a standalone server through manage.py
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment