Add videogame API and register ViewSets for scrobble relationships

VideoGame was missing from the API router, causing
HyperlinkedModelSerializer to fail when generating URLs for scrobble
relationships.

Changes:
- Create videogames/api/ with serializers and views
- Register VideoGameViewSet at /api/v1/videogames/
- Register VideoGameCollectionViewSet at /api/v1/videogame-collections/
- Register VideoGamePlatformViewSet at /api/v1/videogame-platforms/
This commit is contained in:
2026-07-23 21:42:39 -04:00
parent caff69c714
commit 408475f159
4 changed files with 49 additions and 0 deletions

View File

View File

@ -0,0 +1,20 @@
from rest_framework import serializers
from videogames.models import VideoGame, VideoGameCollection, VideoGamePlatform
class VideoGameSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = VideoGame
fields = "__all__"
class VideoGameCollectionSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = VideoGameCollection
fields = "__all__"
class VideoGamePlatformSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = VideoGamePlatform
fields = "__all__"

View File

@ -0,0 +1,21 @@
from rest_framework import permissions, viewsets
from videogames.api import serializers
from videogames import models
class VideoGameViewSet(viewsets.ModelViewSet):
queryset = models.VideoGame.objects.all().order_by("-created")
serializer_class = serializers.VideoGameSerializer
permission_classes = [permissions.IsAuthenticated]
class VideoGameCollectionViewSet(viewsets.ModelViewSet):
queryset = models.VideoGameCollection.objects.all().order_by("-created")
serializer_class = serializers.VideoGameCollectionSerializer
permission_classes = [permissions.IsAuthenticated]
class VideoGamePlatformViewSet(viewsets.ModelViewSet):
queryset = models.VideoGamePlatform.objects.all().order_by("-created")
serializer_class = serializers.VideoGamePlatformSerializer
permission_classes = [permissions.IsAuthenticated]

View File

@ -89,6 +89,11 @@ from vrobbler.apps.trails import urls as trails_urls
from vrobbler.apps.trails.api.views import TrailViewSet
from vrobbler.apps.trends import urls as trends_urls
from vrobbler.apps.videogames import urls as videogame_urls
from vrobbler.apps.videogames.api.views import (
VideoGameCollectionViewSet,
VideoGamePlatformViewSet,
VideoGameViewSet,
)
from vrobbler.apps.videos import urls as video_urls
from vrobbler.apps.videos.api.views import (
ChannelViewSet,
@ -151,6 +156,9 @@ router.register(r"puzzle-manufacturers", PuzzleManufacturerViewSet)
router.register(r"puzzles", PuzzleViewSet)
router.register(r"bricksets", BrickSetViewSet)
router.register(r"lifeevents", LifeEventViewSet)
router.register(r"videogames", VideoGameViewSet)
router.register(r"videogame-collections", VideoGameCollectionViewSet)
router.register(r"videogame-platforms", VideoGamePlatformViewSet)
router.register(r"birds", BirdViewSet)
router.register(r"birding-locations", BirdingLocationViewSet)