mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 21:27:49 +02:00
Add REST API to roster
This commit is contained in:
18
dcc/roster/serializers.py
Normal file
18
dcc/roster/serializers.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from rest_framework import serializers
|
||||
from roster.models import Cab
|
||||
from metadata.serializers import (
|
||||
ManufacturerSerializer, CompanySerializer, DecoderSerializer)
|
||||
|
||||
|
||||
class CabSerializer(serializers.ModelSerializer):
|
||||
manufacturer = ManufacturerSerializer()
|
||||
decoder = DecoderSerializer()
|
||||
company = CompanySerializer()
|
||||
# manufacturer = serializers.StringRelatedField()
|
||||
# decoder = serializers.StringRelatedField()
|
||||
# company = serializers.StringRelatedField()
|
||||
|
||||
class Meta:
|
||||
model = Cab
|
||||
fields = "__all__"
|
||||
read_only_fields = ("identifier", "creation_time", "updated_time")
|
10
dcc/roster/urls.py
Normal file
10
dcc/roster/urls.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django.urls import path
|
||||
from roster.views import (
|
||||
RosterList, RosterGet, RosterAddress, RosterIdentifier)
|
||||
|
||||
urlpatterns = [
|
||||
path('list', RosterList.as_view()),
|
||||
path('get/<str:uuid>', RosterGet.as_view()),
|
||||
path('address/<int:address>', RosterAddress.as_view()),
|
||||
path('identifier/<str:identifier>', RosterIdentifier.as_view()),
|
||||
]
|
@@ -1,3 +1,27 @@
|
||||
from django.shortcuts import render
|
||||
from rest_framework.generics import ListCreateAPIView, RetrieveUpdateAPIView
|
||||
|
||||
# Create your views here.
|
||||
from roster.models import Cab
|
||||
from roster.serializers import CabSerializer
|
||||
|
||||
|
||||
class RosterList(ListCreateAPIView):
|
||||
queryset = Cab.objects.all()
|
||||
serializer_class = CabSerializer
|
||||
|
||||
|
||||
class RosterGet(RetrieveUpdateAPIView):
|
||||
queryset = Cab.objects.all()
|
||||
serializer_class = CabSerializer
|
||||
lookup_field = 'uuid'
|
||||
|
||||
|
||||
class RosterAddress(RetrieveUpdateAPIView):
|
||||
queryset = Cab.objects.all()
|
||||
serializer_class = CabSerializer
|
||||
lookup_field = 'address'
|
||||
|
||||
|
||||
class RosterIdentifier(RetrieveUpdateAPIView):
|
||||
queryset = Cab.objects.all()
|
||||
serializer_class = CabSerializer
|
||||
lookup_field = 'identifier'
|
||||
|
Reference in New Issue
Block a user