1
Fork 0
mirror of https://github.com/Steffo99/sophon.git synced 2024-12-22 06:44:21 +00:00

Add basic API methods

This commit is contained in:
Steffo 2021-04-05 19:35:16 +02:00
parent 7b273b5b3b
commit 2dac9173c9
4 changed files with 65 additions and 3 deletions

View file

@ -0,0 +1,31 @@
from rest_framework import serializers
from . import models
class DataSourceSerializer(serializers.ModelSerializer):
"""
Serializer for :class:`.models.DataSource` .
"""
class Meta:
model = models.DataSource
fields = [
"pandasdmx_id",
"builtin",
"settings",
]
class ProjectSerializer(serializers.ModelSerializer):
"""
Serializer for :class:`.models.Project` .
"""
class Meta:
model = models.Project
fields = [
"id",
"name",
"description",
"sources",
]

13
sophon/core/urls.py Normal file
View file

@ -0,0 +1,13 @@
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from . import views
router = DefaultRouter()
router.register("projects", views.ProjectViewSet)
router.register("datasources", views.DataSourceViewSet)
urlpatterns = [
path("", include(router.urls))
]

View file

@ -1,3 +1,20 @@
from django.shortcuts import render from rest_framework import viewsets, permissions
from . import models, serializers
# Create your views here.
class ProjectViewSet(viewsets.ModelViewSet):
"""
Viewset for :class:`.models.Project` instances.
"""
queryset = models.Project.objects.all()
serializer_class = serializers.ProjectSerializer
permission_classes = []
class DataSourceViewSet(viewsets.ModelViewSet):
"""
Viewset for :class:`.models.DataSource` instances.
"""
queryset = models.DataSource.objects.all()
serializer_class = serializers.DataSourceSerializer
permission_classes = []

View file

@ -18,5 +18,6 @@ from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('api-auth/', include("rest_framework.urls")) path('api-auth/', include("rest_framework.urls")),
path('api/', include("sophon.core.urls")),
] ]