add: default value to tournament.name

This commit is contained in:
starnakin 2023-12-20 22:49:48 +01:00
parent 789a83cb41
commit 5ba432e9fd

View File

@ -7,6 +7,7 @@ class TournamentSerializer(serializers.ModelSerializer):
level = serializers.ReadOnlyField() level = serializers.ReadOnlyField()
started = serializers.ReadOnlyField() started = serializers.ReadOnlyField()
finished = serializers.ReadOnlyField() finished = serializers.ReadOnlyField()
name = serializers.CharField(default="")
class Meta: class Meta:
model = TournamentModel model = TournamentModel
@ -20,3 +21,18 @@ class TournamentSerializer(serializers.ModelSerializer):
break break
levels.append(level) levels.append(level)
return levels return levels
def validate_nb_players(self, value: int):
if (value < 2):
raise serializers.ValidationError("The numbers of players must be greather than 2.")
return value
def validate_nb_players_by_game(self, value: int):
if (value < 2):
raise serializers.ValidationError("The numbers of players by game must be greather than 2.")
nb_players: str = self.initial_data.get("nb_players")
if (nb_players is not None and nb_players.isnumeric()):
nb_players: int = int(nb_players)
if (value > nb_players):
raise serializers.ValidationError("The numbers of players by game must be smaller than the numbers of players.")
return value