Skip to content

Instantly share code, notes, and snippets.

@michaelhelmick
Created April 2, 2021 20:51
Show Gist options
  • Save michaelhelmick/75e5f773dd89ee862e8ecb47ae6aad3d to your computer and use it in GitHub Desktop.
Save michaelhelmick/75e5f773dd89ee862e8ecb47ae6aad3d to your computer and use it in GitHub Desktop.
Bad example of views.py
from rest_framework import viewsets
class GameViewSet(viewsets.ReadOnlyModelViewSet):
"""Game viewset."""
queryset = Game.objects.all()
serializer_class = GameSerializer
def get_serializer_class(self):
"""Determine serializer class."""
if self.request.version == "1.1.0":
return TeeBallSupportedGameSerializer
elif self.request.version == "2.0.0":
return RevampedGameSerializer
return GameSerializer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment