20 lines
532 B
Python
20 lines
532 B
Python
from rest_framework import serializers
|
|
from .models import TournamentModel
|
|
|
|
class TournamentSerializer(serializers.ModelSerializer):
|
|
|
|
levels = serializers.SerializerMethodField()
|
|
|
|
class Meta:
|
|
model = TournamentModel
|
|
fields = ["name", "nb_players", "nb_players_by_game", "level", "started", "finished", "levels"]
|
|
|
|
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
|