Only returns board game when game is finished
This commit is contained in:
@@ -1,12 +1,19 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from game.models import Game, GameEvent
|
||||
from game.models import Game, GameEvent, GameStatuses
|
||||
|
||||
|
||||
class GameSerializer(serializers.ModelSerializer):
|
||||
def to_representation(self, instance):
|
||||
response = super().to_representation(instance)
|
||||
if not response["status"] == GameStatuses.FINISHED:
|
||||
del response["board"]
|
||||
|
||||
return response
|
||||
|
||||
class Meta:
|
||||
model = Game
|
||||
exclude = ["board"]
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class GameEventSerializer(serializers.ModelSerializer):
|
||||
|
||||
Reference in New Issue
Block a user