class Photo(db.Model): photo_id = db.Column(db.Integer, primary_key=True) photo_path = db.Column(db.String, unique=True) upload_date = db.Column(db.DateTime, default=db.func.current_timestamp()) uploaded_by = db.Column(db.Integer, db.ForeignKey('users.user_id')) tags = db.relationship("Tag") liked_by = db.relationship("Like") album_id = db.Column(db.Integer, db.ForeignKey('album.album_id')) def __init__(self, photo_path, uploaded_by, album_id): self.photo_path = photo_path self.uploaded_by = uploaded_by self.album_id = album_id
class Tag(db.Model): tag_id = db.Column(db.Integer, primary_key=True) photo_id = db.Column(db.Integer, db.ForeignKey('photo.photo_id')) tag_desc = db.Column(db.String) def __init__(self, photo_id, tag_desc): self.photo_id = photo_id self.tag_desc = tag_desc
class Like(db.Model): like_id = db.Column(db.Integer, primary_key=True) photo_id = db.Column(db.Integer, db.ForeignKey('photo.photo_id')) liked_by = db.Column(db.String, unique=True) def __init__(self, photo_id, liked_by): self.photo_id = photo_id self.liked_by = liked_by
class SharedPhoto(db.Model): id = db.Column(db.Integer, primary_key=True) photo_id = db.Column(db.Integer, db.ForeignKey('photo.photo_id')) share_key = db.Column(db.String, nullable=False) share_date = db.Column(db.DateTime, default=db.func.current_timestamp()) def __init__(self, photo_id, share_key): self.photo_id = photo_id self.share_key = share_key
class Album(db.Model): album_id = db.Column(db.Integer, primary_key=True) album_name = db.Column(db.String, unique=True) owner = db.Column(db.Integer, db.ForeignKey('users.user_id')) # TODO album cover is set to first photo in the album # cover = db.Column(Integer, ForeignKey('photo.photo_id')) photos = db.relationship("Photo") def __init__(self, album_name, owner): self.album_name = album_name self.owner = owner