Commit cba0b05d authored by olavhdi's avatar olavhdi
Browse files

added serializers to the facility views

parent a8ef0f03
from rest_framework import serializers
from .models import Facility
class FacilityPostSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Facility
fields = [
"name",
"date",
"description",
"latitude",
"longitude",
"image1",
"image2",
"image3",
"image4",
"image5",
]
def create(self, validated_data):
return Facility.objects.create(**validated_data)
class FacilityGetSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Facility
fields = [
"name",
"date",
"description",
"latitude",
"longitude",
"image1",
"image2",
"image3",
"image4",
"image5",
]
\ No newline at end of file
...@@ -4,15 +4,15 @@ from rest_framework import generics, mixins ...@@ -4,15 +4,15 @@ from rest_framework import generics, mixins
from rest_framework import permissions from rest_framework import permissions
from rest_framework.decorators import api_view from rest_framework.decorators import api_view
from rest_framework.reverse import reverse from rest_framework.reverse import reverse
from facilities.models import Facility from .models import Facility
from rest_framework.response import Response from rest_framework.response import Response
from .serializers import FacilityGetSerializer, FacilityPostSerializer
@api_view(["GET"]) @api_view(["GET"])
def api_root(request, format=None): def api_root(request, format=None):
return Response( return Response(
{ {
"users": reverse("user-list", request=request, format=format),
"facilities": reverse("facility-list", request=request, format=format), "facilities": reverse("facility-list", request=request, format=format),
} }
) )
...@@ -25,7 +25,7 @@ class FacilityGeneration( ...@@ -25,7 +25,7 @@ class FacilityGeneration(
HTTP methods: POST HTTP methods: POST
""" """
serializer_class = FacilityPostSerializer
queryset = Facility.objects.all() queryset = Facility.objects.all()
permission_classes = [permissions.IsAdminUser] permission_classes = [permissions.IsAdminUser]
...@@ -40,7 +40,7 @@ class FacilityList( ...@@ -40,7 +40,7 @@ class FacilityList(
HTTP methods: GET HTTP methods: GET
""" """
serializer_class = FacilityGetSerializer
queryset = Facility.objects.all() queryset = Facility.objects.all()
permission_classes = [permissions.IsAuthenticated] permission_classes = [permissions.IsAuthenticated]
ordering_fields = ["name", "date"] ordering_fields = ["name", "date"]
...@@ -57,7 +57,7 @@ class FacilitySingle( ...@@ -57,7 +57,7 @@ class FacilitySingle(
HTTP methods: GET HTTP methods: GET
""" """
serializer_class = FacilityGetSerializer
queryset = Facility.objects.all() queryset = Facility.objects.all()
permission_classes = [permissions.IsAuthenticated] permission_classes = [permissions.IsAuthenticated]
......
Supports Markdown
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