from __future__ import print_function

import sqlalchemy as sa
from sqlalchemy.orm import scoped_session, sessionmaker, DeclarativeBase

from sqlalchemy_mixins import ReprMixin

class Base(DeclarativeBase):
    __abstract__ = True
engine = sa.create_engine('sqlite:///:memory:')
session = scoped_session(sessionmaker(bind=engine))


class BaseModel(Base, ReprMixin):
    __abstract__ = True
    __repr__ = ReprMixin.__repr__
    pass


class User(BaseModel):
    __tablename__ = 'user'
    __repr_attrs__ = ['name']

    id = sa.Column(sa.Integer, primary_key=True)
    name = sa.Column(sa.String)
    posts = sa.orm.relationship('Post', backref='user')


class Post(BaseModel):
    __tablename__ = 'post'
    __repr_attrs__ = ['body', 'user']
    __repr_max_length__ = 25

    id = sa.Column(sa.Integer, primary_key=True)
    body = sa.Column(sa.String)
    user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))


Base.metadata.create_all(engine)

bob = User(name='Bob')
session.add(bob)
session.flush()

post1 = Post(body='Post 1', user=bob)
session.add(post1)
session.flush()

post2 = Post(body='Post 2 long-long body', user=bob)
session.add(post2)
session.flush()

# <User #1 'Bob'>
print(bob)

# <Post #1 body: 'Post 1' user: <User #1 ...>
print(post1)

# <Post #2 body: 'Post 2 long-...' user: <User #1 ...>
print(post2)

ab8ff1759ac89accfb2ae5460081ef7ac41fbb76
<mask token>


class Base(DeclarativeBase):
    <mask token>


<mask token>


class BaseModel(Base, ReprMixin):
    __abstract__ = True
    __repr__ = ReprMixin.__repr__
    pass


class User(BaseModel):
    __tablename__ = 'user'
    __repr_attrs__ = ['name']
    id = sa.Column(sa.Integer, primary_key=True)
    name = sa.Column(sa.String)
    posts = sa.orm.relationship('Post', backref='user')


class Post(BaseModel):
    __tablename__ = 'post'
    __repr_attrs__ = ['body', 'user']
    __repr_max_length__ = 25
    id = sa.Column(sa.Integer, primary_key=True)
    body = sa.Column(sa.String)
    user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))


<mask token>

<mask token>


class Base(DeclarativeBase):
    __abstract__ = True


<mask token>


class BaseModel(Base, ReprMixin):
    __abstract__ = True
    __repr__ = ReprMixin.__repr__
    pass


class User(BaseModel):
    __tablename__ = 'user'
    __repr_attrs__ = ['name']
    id = sa.Column(sa.Integer, primary_key=True)
    name = sa.Column(sa.String)
    posts = sa.orm.relationship('Post', backref='user')


class Post(BaseModel):
    __tablename__ = 'post'
    __repr_attrs__ = ['body', 'user']
    __repr_max_length__ = 25
    id = sa.Column(sa.Integer, primary_key=True)
    body = sa.Column(sa.String)
    user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))


<mask token>

<mask token>


class Base(DeclarativeBase):
    __abstract__ = True


<mask token>


class BaseModel(Base, ReprMixin):
    __abstract__ = True
    __repr__ = ReprMixin.__repr__
    pass


class User(BaseModel):
    __tablename__ = 'user'
    __repr_attrs__ = ['name']
    id = sa.Column(sa.Integer, primary_key=True)
    name = sa.Column(sa.String)
    posts = sa.orm.relationship('Post', backref='user')


class Post(BaseModel):
    __tablename__ = 'post'
    __repr_attrs__ = ['body', 'user']
    __repr_max_length__ = 25
    id = sa.Column(sa.Integer, primary_key=True)
    body = sa.Column(sa.String)
    user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))


Base.metadata.create_all(engine)
<mask token>
session.add(bob)
session.flush()
<mask token>
session.add(post1)
session.flush()
<mask token>
session.add(post2)
session.flush()
print(bob)
print(post1)
print(post2)

from __future__ import print_function
import sqlalchemy as sa
from sqlalchemy.orm import scoped_session, sessionmaker, DeclarativeBase
from sqlalchemy_mixins import ReprMixin


class Base(DeclarativeBase):
    __abstract__ = True


engine = sa.create_engine('sqlite:///:memory:')
session = scoped_session(sessionmaker(bind=engine))


class BaseModel(Base, ReprMixin):
    __abstract__ = True
    __repr__ = ReprMixin.__repr__
    pass


class User(BaseModel):
    __tablename__ = 'user'
    __repr_attrs__ = ['name']
    id = sa.Column(sa.Integer, primary_key=True)
    name = sa.Column(sa.String)
    posts = sa.orm.relationship('Post', backref='user')


class Post(BaseModel):
    __tablename__ = 'post'
    __repr_attrs__ = ['body', 'user']
    __repr_max_length__ = 25
    id = sa.Column(sa.Integer, primary_key=True)
    body = sa.Column(sa.String)
    user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))


Base.metadata.create_all(engine)
bob = User(name='Bob')
session.add(bob)
session.flush()
post1 = Post(body='Post 1', user=bob)
session.add(post1)
session.flush()
post2 = Post(body='Post 2 long-long body', user=bob)
session.add(post2)
session.flush()
print(bob)
print(post1)
print(post2)

from __future__ import print_function

import sqlalchemy as sa
from sqlalchemy.orm import scoped_session, sessionmaker, DeclarativeBase

from sqlalchemy_mixins import ReprMixin

class Base(DeclarativeBase):
    __abstract__ = True
engine = sa.create_engine('sqlite:///:memory:')
session = scoped_session(sessionmaker(bind=engine))


class BaseModel(Base, ReprMixin):
    __abstract__ = True
    __repr__ = ReprMixin.__repr__
    pass


class User(BaseModel):
    __tablename__ = 'user'
    __repr_attrs__ = ['name']

    id = sa.Column(sa.Integer, primary_key=True)
    name = sa.Column(sa.String)
    posts = sa.orm.relationship('Post', backref='user')


class Post(BaseModel):
    __tablename__ = 'post'
    __repr_attrs__ = ['body', 'user']
    __repr_max_length__ = 25

    id = sa.Column(sa.Integer, primary_key=True)
    body = sa.Column(sa.String)
    user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))


Base.metadata.create_all(engine)

bob = User(name='Bob')
session.add(bob)
session.flush()

post1 = Post(body='Post 1', user=bob)
session.add(post1)
session.flush()

post2 = Post(body='Post 2 long-long body', user=bob)
session.add(post2)
session.flush()

# <User #1 'Bob'>
print(bob)

# <Post #1 body: 'Post 1' user: <User #1 ...>
print(post1)

# <Post #2 body: 'Post 2 long-...' user: <User #1 ...>
print(post2)
