Skip to content

Instantly share code, notes, and snippets.

@michaelhelmick
Last active April 2, 2021 20:44
Show Gist options
  • Save michaelhelmick/6503d3d134dc9e5fe9988704809b415d to your computer and use it in GitHub Desktop.
Save michaelhelmick/6503d3d134dc9e5fe9988704809b415d to your computer and use it in GitHub Desktop.
Bad example
from rest_framework import viewsets
class GameViewSet(viewsets.ReadOnlyModelViewSet):
"""Game viewset."""
queryset = Game.objects.all()
serializer_class = GameSerializer
def get_queryset(self):
"""Filter class queryset."""
if self.action == "list":
if self.request.version != Game.TEEBALL_INTRODUCED_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