python-gallery/onlylegs/models.py

121 lines
3.1 KiB
Python
Raw Permalink Normal View History

"""
OnlyLegs - Database models and ions for SQLAlchemy
"""
from uuid import uuid4
from flask_login import UserMixin
from onlylegs.extensions import db
2023-09-24 18:53:14 +00:00
class AlbumJunction(db.Model):
"""
2023-08-04 17:34:08 +00:00
Junction table for picturess and albums
Joins with picturess and albums
"""
2023-04-12 15:18:13 +00:00
2023-08-04 17:34:08 +00:00
__tablename__ = "album_junction"
id = db.Column(db.Integer, primary_key=True)
2023-08-04 17:34:08 +00:00
album_id = db.Column(db.Integer, db.ForeignKey("albums.id"))
picture_id = db.Column(db.Integer, db.ForeignKey("pictures.id"))
date_added = db.Column(
db.DateTime,
nullable=False,
server_default=db.func.now(), # pylint: disable=E1102
)
2023-09-24 18:53:14 +00:00
class Pictures(db.Model):
"""
2023-08-04 17:34:08 +00:00
Pictures table
"""
2023-04-12 15:18:13 +00:00
2023-08-04 17:34:08 +00:00
__tablename__ = "pictures"
id = db.Column(db.Integer, primary_key=True)
2023-08-04 17:34:08 +00:00
author_id = db.Column(db.Integer, db.ForeignKey("users.id"))
2023-04-12 15:18:13 +00:00
filename = db.Column(db.String, unique=True, nullable=False)
mimetype = db.Column(db.String, nullable=False)
colours = db.Column(db.PickleType, nullable=False)
2023-04-12 15:18:13 +00:00
description = db.Column(db.String, nullable=False)
alt = db.Column(db.String, nullable=False)
2023-04-12 15:18:13 +00:00
created_at = db.Column(
db.DateTime,
nullable=False,
server_default=db.func.now(), # pylint: disable=E1102
)
2023-04-12 15:18:13 +00:00
2023-08-04 17:34:08 +00:00
album_fk = db.relationship("AlbumJunction", backref="pictures")
2023-09-24 18:53:14 +00:00
exif_fk = db.relationship("Exif", backref="pictures")
2023-04-12 15:18:13 +00:00
2023-09-24 18:53:14 +00:00
class Exif(db.Model):
"""
Exif data for pictures
"""
__tablename__ = "exif"
id = db.Column(db.Integer, primary_key=True)
picture_id = db.Column(db.Integer, db.ForeignKey("pictures.id"))
key = db.Column(db.String, nullable=False)
value = db.Column(db.PickleType, nullable=False)
2023-09-24 18:53:14 +00:00
class Albums(db.Model):
"""
2023-08-04 17:34:08 +00:00
albums table
"""
2023-04-12 15:18:13 +00:00
2023-08-04 17:34:08 +00:00
__tablename__ = "albums"
id = db.Column(db.Integer, primary_key=True)
2023-04-12 15:18:13 +00:00
name = db.Column(db.String, nullable=False)
description = db.Column(db.String, nullable=False)
2023-04-12 15:18:13 +00:00
2023-08-04 17:34:08 +00:00
author_id = db.Column(db.Integer, db.ForeignKey("users.id"))
created_at = db.Column(
db.DateTime,
nullable=False,
server_default=db.func.now(), # pylint: disable=E1102
)
2023-04-12 15:18:13 +00:00
2023-08-04 17:34:08 +00:00
album_fk = db.relationship("AlbumJunction", backref="albums")
2023-09-24 18:53:14 +00:00
class Users(db.Model, UserMixin):
"""
2023-08-04 17:34:08 +00:00
Users table
"""
2023-04-12 15:18:13 +00:00
2023-08-04 17:34:08 +00:00
__tablename__ = "users"
# Gallery used information
id = db.Column(db.Integer, primary_key=True)
alt_id = db.Column(db.String, unique=True, nullable=False, default=str(uuid4()))
2023-04-12 15:18:13 +00:00
2023-04-20 19:21:28 +00:00
picture = db.Column(db.String, default=None)
colour = db.Column(db.PickleType, default=None)
2023-04-20 19:21:28 +00:00
banner = db.Column(db.String, default=None)
2023-04-20 17:38:44 +00:00
username = db.Column(db.String, unique=True, nullable=False)
email = db.Column(db.String, unique=True, nullable=False)
password = db.Column(db.String, nullable=False)
joined_at = db.Column(
db.DateTime,
nullable=False,
server_default=db.func.now(), # pylint: disable=E1102
)
2023-04-12 15:18:13 +00:00
2023-08-04 17:34:08 +00:00
pictures_fk = db.relationship("Pictures", backref="author")
albums_fk = db.relationship("Albums", backref="author")
def get_id(self):
return str(self.alt_id)