Ejemplo n.º 1
0
class Users_Users(db.Model):

    __tablename__ = 'users_users'

    id = db.Column(db.Integer, primary_key=True)
    follower_id = db.Column(db.Integer,
                            db.ForeignKey('users.id'),
                            index=True,
                            nullable=False)
    followed_id = db.Column(db.Integer,
                            db.ForeignKey('users.id'),
                            index=True,
                            nullable=False)
    is_approved = db.Column(db.Boolean, nullable=False, server_default='True')
    follower = db.relationship("User",
                               foreign_keys=[follower_id],
                               back_populates="followers")
    following = db.relationship("User",
                                foreign_keys=[followed_id],
                                back_populates="following")

    def __init__(self, follower_id, followed_id, is_approved=True):
        self.follower_id = follower_id
        self.followed_id = followed_id
        self.is_approved = is_approved

    def __repr__(self):
        return f"User {self.follower_id} has followed user {self.followed_id}"
Ejemplo n.º 2
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    content = db.Column(db.String(1024))
    image_id = db.Column(db.Integer, db.ForeignKey('image.id'))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    status = db.Column(db.Integer, default=0)  # 0 正常 1 被删除
    user = db.relationship('User')

    def __init__(self, content, image_id, user_id):
        self.content = content
        self.image_id = image_id
        self.user_id = user_id

    def __repr__(self):
        return '<Comment %d %s>' % (self.id, self.content)
Ejemplo n.º 3
0
class Comment(db.Model):
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    content = db.Column(db.String(1024))
    image_id = db.Column(db.Integer, db.ForeignKey('image.id'))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    status = db.Column(db.Integer, default=0) # 0 正常 1删除
    user = db.relationship('User')

    def __init__(self, content, image_id, user_id):
        self.content = content
        self.image_id = image_id
        self.user_id = user_id

    def __repr__(self):
        return ('<Comment%d %s>' % (self.id, self.content)).encode('gbk')
Ejemplo n.º 4
0
class Donation(db.Model):
    __tablename__ = 'donations'

    id = db.Column(db.Integer, primary_key=True)
    donor_id = db.Column(
        db.Integer, db.ForeignKey('users.id'), nullable=False, index=True
    )  # would modify to be nullable and if it's null, it's donated by an anonymous donor
    image_id = db.Column(
        db.Integer,
        db.ForeignKey(
            'images.id'
        ),  # would modify to be nullable and if it's null, just say it's a deleted image (to keep record of deletion)
        nullable=False,
        index=True)
    amount = db.Column(db.Numeric(), nullable=False)

    def __init__(self, donor_id, image_id, amount):
        self.donor_id = donor_id
        self.image_id = image_id
        self.amount = amount
Ejemplo n.º 5
0
class Image(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    url = db.Column(db.String(512))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    create_date = db.Column(db.DateTime)
    comments = db.relationship('Comment')

    def __init__(self, url, user_id):
        self.url = url
        self.user_id = user_id
        self.create_date = datetime.datetime.now()

    def __repr__(self):
        return '<Image %d %s>' % (self.id, self.url)
Ejemplo n.º 6
0
class UserFollowing(db.Model):
    __tablename__ = 'user_followings'

    id = db.Column(db.Integer, primary_key=True)
    idol_id = db.Column(db.Integer,
                        db.ForeignKey('users.id'),
                        nullable=False,
                        index=True)
    fan_id = db.Column(db.Integer,
                       db.ForeignKey('users.id'),
                       nullable=False,
                       index=True)
    approved = db.Column(db.Boolean, nullable=False, index=True, default=False)

    __table_args__ = (db.Index('ix_unique_idol_fan',
                               'idol_id',
                               'fan_id',
                               unique=True), )

    def __init__(self, idol_id, fan_id, approved):
        self.idol_id = idol_id
        self.fan_id = fan_id
        self.approved = approved
Ejemplo n.º 7
0
class Donation(db.Model):

    __tablename__ = 'donations'

    id = db.Column(db.Integer, primary_key=True)
    sender_id = db.Column(db.Integer,
                          db.ForeignKey('users.id'),
                          nullable=False)
    receiver_id = db.Column(db.Integer,
                            db.ForeignKey('users.id'),
                            nullable=False)
    image_id = db.Column(db.Integer,
                         db.ForeignKey('images.id'),
                         nullable=False)
    amount = db.Column(db.Numeric(), nullable=False)
    currency = db.Column(db.String(3), nullable=False, default='USD')
    donor = db.relationship("User",
                            foreign_keys=[sender_id],
                            back_populates="donations_out")
    receiver = db.relationship("User",
                               foreign_keys=[receiver_id],
                               back_populates="donations_in")

    def __init__(self,
                 sender_id,
                 receiver_id,
                 image_id,
                 amount,
                 currency='USD'):
        self.sender_id = sender_id
        self.receiver_id = receiver_id
        self.image_id = image_id
        self.amount = amount
        self.currency = currency

    def __repr__(self):
        return f"Donation of {self.amount} has been made to {self.receiver_id} by {self.sender_id} for {self.image_id}"
Ejemplo n.º 8
0
class Image(db.Model, UserMixin):
    __tablename__ = 'images'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'),nullable=False)
    image_name = db.Column(db.String(), nullable=False)

    def __init__(self, user_id, image_name):
        self.user_id = user_id
        self.image_name = image_name

    @hybrid_property
    def image_url(self):
        return f"{app.config['S3_LOCATION']}{self.image_name}"

    @staticmethod
    def url(image_name):
      return app.config['S3_LOCATION'] + image_name
Ejemplo n.º 9
0
class Image(db.Model):
    '''
    图片
    '''
    __tablename__ = 'image'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    url = db.Column(db.String(512))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    created_date = db.Column(db.DateTime)
    likecount = db.Column(db.Integer)
    # dislikecount=db.Column(db.Integer) 不统计踩的数目
    comments = db.relationship('Comment')

    def __init__(self, url, user_id):
        self.url = url
        self.user_id = user_id
        self.created_date = datetime.now()
        self.likecount = 0
        self.dislikecount = 0

    def __repr__(self):
        return '<Image%d %s>' % (self.id, self.url)