How to use the marshmallow-sqlalchemy.schema.TableSchemaMeta function in marshmallow-sqlalchemy

To help you get started, we’ve selected a few marshmallow-sqlalchemy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github raminfp / PYHelper / marshmallow-sqlalchemy / schema.py View on Github external
class ModelSchemaMeta(SchemaMeta):

    @classmethod
    def get_fields(mcs, converter, opts, base_fields, dict_cls):
        if opts.model is not None:
            return converter.fields_for_model(
                opts.model,
                fields=opts.fields,
                exclude=opts.exclude,
                include_fk=opts.include_fk,
                base_fields=base_fields,
                dict_cls=dict_cls,
            )
        return dict_cls()

class TableSchema(with_metaclass(TableSchemaMeta, ma.Schema)):

    """Base class for SQLAlchemy model-based Schemas.

    Example: ::

        from marshmallow_sqlalchemy import TableSchema
        from mymodels import engine, users

        class UserSchema(TableSchema):
            class Meta:
                table = users

        schema = UserSchema()

        select = users.select().limit(1)
        user = engine.execute(select).fetchone()