mirror of
https://github.com/Steffo99/sophon.git
synced 2024-12-21 22:34:21 +00:00
✨ Add basic API methods
This commit is contained in:
parent
7b273b5b3b
commit
2dac9173c9
4 changed files with 65 additions and 3 deletions
31
sophon/core/serializers.py
Normal file
31
sophon/core/serializers.py
Normal 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
13
sophon/core/urls.py
Normal 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))
|
||||
]
|
|
@ -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 = []
|
||||
|
|
|
@ -18,5 +18,6 @@ from django.urls import path, include
|
|||
|
||||
urlpatterns = [
|
||||
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")),
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue