2023-12-20 15:09:31 -05:00
|
|
|
from rest_framework import serializers
|
|
|
|
from .models import TournamentModel
|
|
|
|
|
|
|
|
class TournamentSerializer(serializers.ModelSerializer):
|
|
|
|
|
2023-12-20 15:58:52 -05:00
|
|
|
levels = serializers.SerializerMethodField(read_only=True, required=False)
|
|
|
|
level = serializers.ReadOnlyField()
|
|
|
|
started = serializers.ReadOnlyField()
|
|
|
|
finished = serializers.ReadOnlyField()
|
2023-12-20 15:09:31 -05:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = TournamentModel
|
2023-12-20 15:58:52 -05:00
|
|
|
fields = ["name", "nb_players", "nb_players_by_game", "level", "started", "finished", "levels", "id"]
|
2023-12-20 15:09:31 -05:00
|
|
|
|
|
|
|
def get_levels(self, instance):
|
|
|
|
levels: [[int]] = []
|
|
|
|
for i in range(instance.level):
|
|
|
|
level: [int] = instance.get_games_id_by_level(i)
|
|
|
|
if (level == []):
|
|
|
|
break
|
|
|
|
levels.append(level)
|
|
|
|
return levels
|