Installation
pip install marshmallow-sqlalchemy-referential
Sample Usage
import sqlalchemy as sa
from sqlalchemy.ext.declarative import declarative_base
from marshmallow_sqlalchemy_referential import Referential
from marshmallow_sqlalchemy import ModelSchema
from marshmallow import fields
Base = declarative_base()
user_group_assoc = sa.Table(
'user_group_assoc', Base.metadata,
sa.Column('user_id', sa.Integer, sa.ForeignKey('user.id')),
sa.Column('group_id', sa.Integer, sa.ForeignKey('group.id'))
)
class User(Base):
__tablename__ = 'user'
id = sa.Column(sa.Integer(), primary_key=True)
groups = sa.orm.relationship('Group', secondary=user_group_assoc)
class Group(Base):
__tablename__ = 'group'
id = sa.Column(sa.Integer(), primary_key=True)
users = sa.orm.relationship('User', secondary=user_group_assoc)
class GroupSchema(ModelSchema):
class Meta():
dump_only = ['id']
id = fields.Integer()
class UserSchema(ModelSchema):
class Meta():
dump_only = ['id']
id = fields.Integer()
groups = Referential(GroupSchema, model=Group, many=True)
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file marshmallow-sqlalchemy-referential-1.0.5.tar.gz.
File metadata
- Download URL: marshmallow-sqlalchemy-referential-1.0.5.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06c27feaeca029b9616a10fa4b99a351064ae6db4b6bdeb56e3ad1245b783d2f
|
|
| MD5 |
5f82aebff276a6c57b3a239e45855c86
|
|
| BLAKE2b-256 |
2f28def2862238bef90a3da78a3055fcdaa44d05b160fdf18b616962be0f64f8
|