class PlaySchema(ma.SQLAlchemyAutoSchema): id = ma.Int(dump_only=True) turn_number = ma.Int(required=True) score = ma.Int(required=True) cumulative_score = ma.Int() word = ma.Nested("WordSchema", required=True) game = ma.Nested("GameSchema", exclude=("plays", ), required=True) player = ma.Nested("PlayerSchema", exclude=("plays", ), required=True) class Meta: model = Play sqla_session = db.session load_instance = True include_fk = True include_relationships = True exclude = ("word_id", "game_id", "player_id")
class PlayerSchema(ma.SQLAlchemyAutoSchema): id = ma.Int(dump_only=True) name = ma.String(required=True) plays = ma.Nested("PlaySchema", many=True) class Meta: model = Player sqla_session = db.session load_instance = True include_relationships = True
class GameSchema(ma.SQLAlchemyAutoSchema): id = ma.Int(dump_only=True) date = ma.DateTime(required=True) gametype = EnumField(GametypeEnum, by_value=True, required=True) winner = ma.Nested("PlayerSchema") players = ma.Nested("PlayerSchema", many=True) plays = ma.Nested("PlaySchema", many=True) @validates("date") def validate_date(self, date): if date > datetime.now(): raise ValidationError("Date cannot be in the future") class Meta: model = Game sqla_session = db.session load_instance = True include_fk = True include_relationships = True
class WordSchema(ma.SQLAlchemyAutoSchema): id = ma.Integer(dump_only=True) word = ma.String(required=True) language = ma.Nested("LanguageSchema", required=True) class Meta: model = Word sqla_session = db.session load_instance = True include_relationships = True include_fk = True unknown = RAISE
class PlayerPaginationSchema(PaginationSchema): data = ma.Nested("PlayerSchema", attribute="items", many=True)
class WordPaginationSchema(PaginationSchema): data = ma.Nested("WordSchema", attribute="items", many=True)
class GamePaginationSchema(PaginationSchema): data = ma.Nested("GameSchema", attribute="items", many=True)