Last active
April 2, 2021 20:44
-
-
Save michaelhelmick/17c95d0c821844ebed8b6971d79aedad to your computer and use it in GitHub Desktop.
views.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import viewsets | |
from semantic_version import SimpleSpec, Version | |
class GameViewSet(viewsets.ReadOnlyModelViewSet): | |
"""Game viewset.""" | |
queryset = Game.objects.all() | |
serializer_class = GameSerializer | |
def get_queryset(self): | |
"""Filter class queryset.""" | |
if self.action == "list": | |
teeball_not_introduced = SimpleSpec(f"<{Game.TEEBALL_INTRODUCED_VERSION}") | |
if teeball_not_introduced.match(Version(self.request.version)): | |
self.queryset = self.queryset.exclude(type=Game.GameType.TEEBALL) | |
return self.queryset |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment