diff --git a/core/serializers/SpaceSerializer.py b/core/serializers/SpaceSerializer.py index d07d2f8..3229802 100644 --- a/core/serializers/SpaceSerializer.py +++ b/core/serializers/SpaceSerializer.py @@ -2,7 +2,12 @@ from rest_framework import serializers from core.models.Space import Space +from core.serializers.AssetBundleRoomSerializer import AssetBundleRoomSerializer + class SpaceSerializer(serializers.ModelSerializer): + + assetBundleRoomId = AssetBundleRoomSerializer() # Nested serializer for AssetBundleRoom + class Meta: model = Space fields = ['userId', 'assetBundleRoomId', 'name', 'description', 'capacity'] diff --git a/core/views/spaceView.py b/core/views/spaceView.py index b74aee8..462a8d3 100644 --- a/core/views/spaceView.py +++ b/core/views/spaceView.py @@ -13,14 +13,15 @@ from core.serializers.SpaceSerializer import SpaceSerializer + @api_view(['GET']) @authentication_classes([SessionAuthentication, TokenAuthentication]) @permission_classes([IsAuthenticated]) def getSpaces(request): - # Get the spaces associated with the authenticated user - spaces = Space.objects.filter(userId=request.user) # Filter spaces by the authenticated user + # Get the spaces associated with the authenticated user and join with AssetBundleRoom data + spaces = Space.objects.filter(userId=request.user).select_related('assetBundleRoomId') - # Serialize the spaces + # Serialize the spaces and include all fields from the related AssetBundleRoom serializer = SpaceSerializer(spaces, many=True) # Return the serialized data as a response