Skip to content

Commit

Permalink
Cyberstorm API: add CyberstormPackageCategorySerializer
Browse files Browse the repository at this point in the history
It felt a bit dirty to import such a simple serializer from another
app, especially since that serializer is marked experimental.

Refs TS-1860
  • Loading branch information
anttimaki committed Oct 23, 2023
1 parent 8637060 commit 640a110
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 3 additions & 7 deletions django/thunderstore/api/cyberstorm/serializers/community.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from rest_framework import serializers

from thunderstore.community.api.experimental.serializers import (
PackageCategoryExperimentalSerializer,
)
from thunderstore.community.models import PackageCategory
from thunderstore.repository.api.experimental.serializers import (
CommunityFilteredModelChoiceField,
from thunderstore.api.cyberstorm.serializers.shared import (
CyberstormPackageCategorySerializer,
)


Expand All @@ -19,7 +15,7 @@ class CyberstormCommunitySerializer(serializers.Serializer):
icon_url = serializers.CharField(required=False)
total_download_count = serializers.SerializerMethodField()
total_package_count = serializers.SerializerMethodField()
package_categories = PackageCategoryExperimentalSerializer(many=True)
package_categories = CyberstormPackageCategorySerializer(many=True)

def get_total_download_count(self, obj) -> int:
return obj.aggregated.download_count
Expand Down
10 changes: 10 additions & 0 deletions django/thunderstore/api/cyberstorm/serializers/shared.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
Do not import/export these through __init__.py to avoid circular imports
in other serializer files.
"""
from rest_framework import serializers


class CyberstormPackageCategorySerializer(serializers.Serializer):
name = serializers.CharField()
slug = serializers.SlugField()

0 comments on commit 640a110

Please sign in to comment.