Example #1
0
class Deal(db.Model):
    # 1 user to multi deals
    id = db.Column(db.Integer, primary_key=True)
    time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)

    by_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    item_id = db.Column(db.Integer, db.ForeignKey('post.id'))
Example #2
0
class Deal(db.Model):
    # 1 user to multi deals
    id = db.Column(db.Integer, primary_key=True)
    time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)

    # link the deal to the user who makes the deal
    by_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    by = db.relationship('User', backref='deals')

    # link the deal to the item
    item_id = db.Column(db.Integer, db.ForeignKey('post.id'))
    item = db.relationship('Post', backref='deals')
    admin = db.Column(db.Integer, db.ForeignKey('admin.id'))
Example #3
0
class User(db.Model, UserMixin):
    __searchable__ = ['username']
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    password = db.Column(db.String(60), nullable=False)
    image_file = db.Column(db.String,
                           nullable=False,
                           default='default profile.jpg')
    # relationships
    admin = db.Column(db.Integer, db.ForeignKey('admin.id'))
Example #4
0
class Category(db.Model):
    __tablename__ = 'category'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30), unique=True)
    description = db.Column(db.String(100), nullable=True)
    image_file = db.Column(db.String,
                           nullable=False,
                           default='default category.jpg')
    #relationships
    post_id = db.relationship("Post",
                              secondary=post_category_collections,
                              backref='categories',
                              lazy='dynamic')
    admin = db.Column(db.Integer, db.ForeignKey('admin.id'))
Example #5
0
class Post(db.Model):
    __tablename__ = 'post'
    __searchable__ = ['title', 'subtitle', 'content']
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(20), nullable=False)
    subtitle = db.Column(db.String(100), nullable=False)
    content = db.Column(db.Text, nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    price = db.Column(db.Integer, nullable=False, default=0)
    image_file = db.Column(db.String,
                           nullable=False,
                           default='default post.jpg')
    likes = db.Column(db.Integer, nullable=True, default=0)
    #relationships
    admin = db.Column(db.Integer, db.ForeignKey('admin.id'))
    # category_id = db.relationship("Category", secondary= post_category_collections, backref = "posts", lazy = 'dynamic')
    category_id = db.Column(db.Integer, nullable=True, default='Unclassified')
Example #6
0
    time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)

    # link the deal to the user who makes the deal
    by_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    by = db.relationship('User', backref='deals')

    # link the deal to the item
    item_id = db.Column(db.Integer, db.ForeignKey('post.id'))
    item = db.relationship('Post', backref='deals')
    admin = db.Column(db.Integer, db.ForeignKey('admin.id'))


# post 和 category 实际为多对多,应该创建关联表进行连接
post_category_collections = db.Table(
    "post_category_collections",
    db.Column('post_id', db.Integer, db.ForeignKey("post.id")),
    db.Column('category_id', db.Integer, db.ForeignKey("category.id")))


class Post(db.Model):
    __tablename__ = 'post'
    __searchable__ = ['title', 'subtitle', 'content']
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(20), nullable=False)
    subtitle = db.Column(db.String(100), nullable=False)
    content = db.Column(db.Text, nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    price = db.Column(db.Integer, nullable=False, default=0)
    image_file = db.Column(db.String,