コード例 #1
0
class User(db.Model):
    __tablename__ = 'user'

    user_id = db.Column(db.Integer, primary_key=True)
    public_id = db.Column(db.String(50), unique=True)
    name = db.Column(db.String(userNameMaxLength))
    password = db.Column(db.String(80))
    admin = db.Column(db.Boolean)
    group = db.relationship('Group',
                            backref='owner',
                            lazy=True,
                            cascade='delete')

    def __repr__(self):
        return '<User %r>' % self.name
コード例 #2
0
class Todo(db.Model):
    __tablename__ = 'todo'

    todo_id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String(todoTextMaxLength))
    complete = db.Column(db.Boolean)

    groups = db.relationship(
        'Group',
        secondary=todoGroup,
        lazy='subquery',
        backref=db.backref('groups', lazy=True),
    )

    def __repr__(self):
        return '<Todo %r>' % self.text
コード例 #3
0
class Group(db.Model):
    __tablename__ = 'group'

    group_id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), nullable=False)
    owner_id = db.Column(db.Integer,
                         db.ForeignKey('user.user_id'),
                         nullable=False)

    users = db.relationship(
        'User',
        secondary=userGroup,
        lazy='subquery',
        backref=db.backref('users', lazy=True),
    )

    def __repr__(self):
        return '<Group %r>' % self.name
コード例 #4
0
from collective_todo import db
from wtforms import Form, validators, StringField, FieldList

todoGroup = db.Table(
    'todoGroup',
    db.Column('group_id',
              db.Integer,
              db.ForeignKey('group.group_id'),
              primary_key=True),
    db.Column('todo_id',
              db.Integer,
              db.ForeignKey('todo.todo_id'),
              primary_key=True),
)

todoTextMaxLength = 50


class Todo(db.Model):
    __tablename__ = 'todo'

    todo_id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String(todoTextMaxLength))
    complete = db.Column(db.Boolean)

    groups = db.relationship(
        'Group',
        secondary=todoGroup,
        lazy='subquery',
        backref=db.backref('groups', lazy=True),
    )
コード例 #5
0
from collective_todo import db

userGroup = db.Table(
    'userGroup',
    db.Column('user_id',
              db.Integer,
              db.ForeignKey('user.user_id'),
              primary_key=True),
    db.Column('group_id',
              db.Integer,
              db.ForeignKey('group.group_id'),
              primary_key=True),
)


class Group(db.Model):
    __tablename__ = 'group'

    group_id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), nullable=False)
    owner_id = db.Column(db.Integer,
                         db.ForeignKey('user.user_id'),
                         nullable=False)

    users = db.relationship(
        'User',
        secondary=userGroup,
        lazy='subquery',
        backref=db.backref('users', lazy=True),
    )