diff --git a/django_napse/api/exchanges/__init__.py b/django_napse/api/exchanges/__init__.py deleted file mode 100644 index 2fb79dcf..00000000 --- a/django_napse/api/exchanges/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from .tests import * -from .views import * diff --git a/django_napse/api/exchanges/views/exchange_view.py b/django_napse/api/exchanges/views/exchange_view.py index e1def45e..36422e81 100644 --- a/django_napse/api/exchanges/views/exchange_view.py +++ b/django_napse/api/exchanges/views/exchange_view.py @@ -5,8 +5,6 @@ from django_napse.api.exchanges.serializers import ExchangeAccountDetailSerializer, ExchangeAccountSerializer from django_napse.core.models import ExchangeAccount -# from rest_framework.decorators import action - class ExchangeAccountView(GenericViewSet): permission_classes = [] diff --git a/django_napse/api/spaces/serializers/space_serializers.py b/django_napse/api/spaces/serializers/space_serializers.py index 8536d693..3f664bc5 100644 --- a/django_napse/api/spaces/serializers/space_serializers.py +++ b/django_napse/api/spaces/serializers/space_serializers.py @@ -6,20 +6,23 @@ class SpaceSerializer(serializers.ModelSerializer): fleet_count = serializers.SerializerMethodField(read_only=True) + exchange_account = serializers.CharField(source="exchange_account.uuid", read_only=True) class Meta: model = NapseSpace fields = [ "name", # read-only - "id", + "uuid", "value", "fleet_count", + "exchange_account", ] read_only_fields = [ - "id", + "uuid", "value", "fleet_count", + "exchange_account", ] def get_fleet_count(self, instance) -> int: @@ -28,6 +31,7 @@ def get_fleet_count(self, instance) -> int: class SpaceDetailSerializer(serializers.ModelSerializer): fleets = FleetSerializer(many=True, read_only=True) + exchange_account = serializers.CharField(source="exchange_account.uuid", read_only=True) class Meta: model = NapseSpace @@ -35,14 +39,16 @@ class Meta: "name", "description", # read-only - "id", + "uuid", "value", "created_at", "fleets", + "exchange_account", ] read_only_fields = [ - "id", + "uuid", "value", "fleet", "created_at", + "exchange_account", ] diff --git a/django_napse/api/spaces/views/space_view.py b/django_napse/api/spaces/views/space_view.py index ec05e6c6..6b465e9c 100644 --- a/django_napse/api/spaces/views/space_view.py +++ b/django_napse/api/spaces/views/space_view.py @@ -2,18 +2,22 @@ from rest_framework.response import Response from rest_framework.viewsets import GenericViewSet -from django_napse.api.spaces.serializers import SpaceDetailSerializer, SpaceSerializer from django_napse.core.models import NapseSpace class SpaceView(GenericViewSet): permission_classes = [] - serializer_class = SpaceSerializer + # serializer_class = SpaceSerializer + + def get_object(self): + return self.get_queryset().get(uuid=self.kwargs["pk"]) def get_queryset(self): return NapseSpace.objects.all() def get_serializer_class(self, *args, **kwargs): + from django_napse.api.spaces.serializers import SpaceDetailSerializer, SpaceSerializer + actions: dict = { "list": SpaceSerializer, "retrieve": SpaceDetailSerializer, @@ -22,12 +26,13 @@ def get_serializer_class(self, *args, **kwargs): return result if result else super().get_serializer_class() def list(self, request): - serializer = self.serializer_class(self.get_queryset(), many=True) + serializer = self.get_serializer(self.get_queryset(), many=True) return Response(serializer.data, status=status.HTTP_200_OK) def retrieve(self, request, pk=None): instance = self.get_object() serializer = self.get_serializer(instance) + print(serializer.data) return Response(serializer.data, status=status.HTTP_200_OK) def create(self, request, *args, **kwargs):