supercontest.models.schemas
Defines the serialization of models.
In most cases, app logic is kept to a minimum and frontend views map as close as possible to DB tables/views. SQLAlchemy Rows are not json-serializable, so we have a few options: parse to json-serializable objects (like dicts), dataclasses, or marshmallow. I’ve chosen the latter, since (as a serialization lib) it has plugins to both flask and sqlalchemy.
By default, marshmallow-sqlalchemy will only include the PK for relationships. I want to
recurse down to include all objects, so I nest all relationships below. This handles all types: one
to one, one to many, many to one, and many to many.
Note, however, the relationships are unidirectional here (in the models they’re bidirectional). In the python ORM, we can have infinitely recursed pointers to the same objects. But when we’re serializing, we can’t have an infinite-length string, so we keep the object hierarchy flowing in a single direction. This is achieved by omitting the nesting on the children, and excluding the backref on the parent. No data is missing - it’s just located in a single place on the parent, rather than both on the parent and child.
So only forward relationships (see models) are nested below, with the backward relationships excluded from the nesting.
Module Attributes
The Marshmallow object used around the app to define schemas and serialize objects. |
Classes
- class supercontest.models.schemas.ContestantSchema(*args, **kwargs)
Bases:
SQLAlchemyAutoSchema- class Meta
Bases:
object- include_fk = True
- include_relationships = True
- model
alias of
Contestant
- sqla_session = <flask_marshmallow.sqla.DummySession object>
- opts: SchemaOpts = <flask_marshmallow.sqla.SQLAlchemyAutoSchemaOpts object>
- class supercontest.models.schemas.CoverageSchema(*args, **kwargs)
Bases:
SQLAlchemyAutoSchema- class Meta
Bases:
object- include_fk = True
- include_relationships = True
- sqla_session = <flask_marshmallow.sqla.DummySession object>
- opts: SchemaOpts = <flask_marshmallow.sqla.SQLAlchemyAutoSchemaOpts object>
- class supercontest.models.schemas.GameSchema(*args, **kwargs)
Bases:
SQLAlchemyAutoSchema- class Meta
Bases:
object- include_fk = True
- include_relationships = True
- sqla_session = <flask_marshmallow.sqla.DummySession object>
- opts: SchemaOpts = <flask_marshmallow.sqla.SQLAlchemyAutoSchemaOpts object>
- class supercontest.models.schemas.LeagueSchema(*args, **kwargs)
Bases:
SQLAlchemyAutoSchema- class Meta
Bases:
object- include_fk = True
- include_relationships = True
- sqla_session = <flask_marshmallow.sqla.DummySession object>
- opts: SchemaOpts = <flask_marshmallow.sqla.SQLAlchemyAutoSchemaOpts object>
- class supercontest.models.schemas.LocationSchema(*args, **kwargs)
Bases:
SQLAlchemyAutoSchema- class Meta
Bases:
object- include_fk = True
- include_relationships = True
- sqla_session = <flask_marshmallow.sqla.DummySession object>
- opts: SchemaOpts = <flask_marshmallow.sqla.SQLAlchemyAutoSchemaOpts object>
- class supercontest.models.schemas.PickSchema(*args, **kwargs)
Bases:
SQLAlchemyAutoSchema- class Meta
Bases:
object- include_fk = True
- include_relationships = True
- sqla_session = <flask_marshmallow.sqla.DummySession object>
- opts: SchemaOpts = <flask_marshmallow.sqla.SQLAlchemyAutoSchemaOpts object>
- class supercontest.models.schemas.PredictionSchema(*args, **kwargs)
Bases:
SQLAlchemyAutoSchema- class Meta
Bases:
object- include_fk = True
- include_relationships = True
- model
alias of
Prediction
- sqla_session = <flask_marshmallow.sqla.DummySession object>
- opts: SchemaOpts = <flask_marshmallow.sqla.SQLAlchemyAutoSchemaOpts object>
- class supercontest.models.schemas.RoleSchema(*args, **kwargs)
Bases:
SQLAlchemyAutoSchema- class Meta
Bases:
object- include_fk = True
- include_relationships = True
- sqla_session = <flask_marshmallow.sqla.DummySession object>
- opts: SchemaOpts = <flask_marshmallow.sqla.SQLAlchemyAutoSchemaOpts object>
- class supercontest.models.schemas.SeasonSchema(*args, **kwargs)
Bases:
SQLAlchemyAutoSchema- class Meta
Bases:
object- include_fk = True
- include_relationships = True
- sqla_session = <flask_marshmallow.sqla.DummySession object>
- opts: SchemaOpts = <flask_marshmallow.sqla.SQLAlchemyAutoSchemaOpts object>
- class supercontest.models.schemas.StatusSchema(*args, **kwargs)
Bases:
SQLAlchemyAutoSchema- class Meta
Bases:
object- include_fk = True
- include_relationships = True
- sqla_session = <flask_marshmallow.sqla.DummySession object>
- opts: SchemaOpts = <flask_marshmallow.sqla.SQLAlchemyAutoSchemaOpts object>
- class supercontest.models.schemas.TeamSchema(*args, **kwargs)
Bases:
SQLAlchemyAutoSchema- class Meta
Bases:
object- include_fk = True
- include_relationships = True
- sqla_session = <flask_marshmallow.sqla.DummySession object>
- opts: SchemaOpts = <flask_marshmallow.sqla.SQLAlchemyAutoSchemaOpts object>
- class supercontest.models.schemas.UserSchema(*args, **kwargs)
Bases:
SQLAlchemyAutoSchema- class Meta
Bases:
object- include_fk = True
- include_relationships = True
- sqla_session = <flask_marshmallow.sqla.DummySession object>
- opts: SchemaOpts = <flask_marshmallow.sqla.SQLAlchemyAutoSchemaOpts object>
- class supercontest.models.schemas.WeekSchema(*args, **kwargs)
Bases:
SQLAlchemyAutoSchema- class Meta
Bases:
object- include_fk = True
- include_relationships = True
- sqla_session = <flask_marshmallow.sqla.DummySession object>
- opts: SchemaOpts = <flask_marshmallow.sqla.SQLAlchemyAutoSchemaOpts object>
- supercontest.models.schemas.ma: Any = <flask_marshmallow.Marshmallow object>
The Marshmallow object used around the app to define schemas and serialize objects.