Skip to main content

marshmallow-sqlalchemy-referential

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)

Metadata

Release files for marshmallow-sqlalchemy-referential 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for marshmallow-sqlalchemy-referential 1.0.5
File Size Uploaded
marshmallow-sqlalchemy-referential-1.0.5.tar.gz 3.9 kB Details

Release files / marshmallow-sqlalchemy-referential-1.0.5.tar.gz

Download URL marshmallow-sqlalchemy-referential-1.0.5.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
06c27feaeca029b9616a10fa4b99a351064ae6db4b6bdeb56e3ad1245b783d2f
BLAKE2b-256 checksum
How to use checksums
2f28def2862238bef90a3da78a3055fcdaa44d05b160fdf18b616962be0f64f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.5 This release

1 release file

1.0.4

1 release file

1.0.2

1 release file

1.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page