A marshmallow-sqlalchemy field allows referential CRUD on relational fields.
Project description
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)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for marshmallow-sqlalchemy-referential-1.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbaa22fadef1019ca9a93181ead7e04c9bddd7f1a0e4643f37b4011079387553 |
|
MD5 | 953e397ad4e588168c70a64d4dac2c0a |
|
BLAKE2b-256 | 872e3ddedcc82b896635efdb3b6153246333f88fa32bd9d61c2cd5d6f1f27450 |