Skip to content

Commit

Permalink
Use TimePlaceModelViewSerializer for response after creating a new Ti…
Browse files Browse the repository at this point in the history
…mePlace
  • Loading branch information
Termuellinator committed Nov 24, 2023
1 parent ec6ebad commit 6007c87
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions apps/timeplace/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def create(self, validated_data):
validated_data['latitude'], validated_data['longitude'])
return super(TimePlaceModelCreateSerializer, self).create(validated_data)

def to_representation(self, instance):
return (TimePlaceModelViewSerializer(context=self.context)
.to_representation(instance))

class TimePlaceModelUpdateSerializer(serializers.ModelSerializer):
"""Serializer to update a TimePlace model instance that takes interests
Expand Down
11 changes: 10 additions & 1 deletion apps/timeplace/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from rest_framework.response import Response
from rest_framework.decorators import action
from geopy.distance import distance
from drf_spectacular.utils import extend_schema, inline_serializer
from drf_spectacular.utils import extend_schema, extend_schema_view, inline_serializer
from drf_spectacular.utils import OpenApiParameter, OpenApiTypes, OpenApiResponse

from apps.match.models import Match
Expand All @@ -30,6 +30,15 @@ class ActivityViewSet(viewsets.ModelViewSet):

serializer_class = serializers.ActivityModelSerializer


@extend_schema_view(
create=extend_schema(
description="""Create a new TimePlace.
Latitude and Longitude are numbers with up to six decimal places.
Latitude needs to be between -90 and 90.
Longitude needs to be between -180 and 180.""",
request=serializers.TimePlaceModelCreateSerializer,
responses={201: serializers.TimePlaceModelViewSerializer}))
class TimePlaceViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.IsAuthenticatedCreateOrSuperOrAuthor,)

Expand Down

0 comments on commit 6007c87

Please sign in to comment.