Skip to content

Instantly share code, notes, and snippets.

@michaelhelmick
Last active April 2, 2021 20:44
Show Gist options
  • Save michaelhelmick/17c95d0c821844ebed8b6971d79aedad to your computer and use it in GitHub Desktop.
Save michaelhelmick/17c95d0c821844ebed8b6971d79aedad to your computer and use it in GitHub Desktop.
views.py
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