class UserProduct(db.Model): __tablename__ = 'user_product' user_id = db.Column(db.String, db.ForeignKey('user.id'), primary_key=True) product_id = db.Column(db.String, db.ForeignKey('product.id'), primary_key=True) category_id = db.Column(db.Integer, db.ForeignKey('category.id')) product = db.relationship("Product", back_populates="users") user = db.relationship("User", back_populates="products") category = db.relationship("Category", back_populates="user_products") active = db.Column(db.Boolean, default=True) wish_list = db.Column(db.Boolean, default=False)
class FriendRelationship(db.Model): __tablename__ = 'friend_relationships' id = db.Column(db.Integer, primary_key=True) owner_id = db.Column(db.String, db.ForeignKey('user.id')) friend_id = db.Column(db.String, db.ForeignKey('user.id')) relation_type = db.Column(db.Integer, db.ForeignKey('friend_relationship_type.id'), nullable=True) active = db.Column(db.Boolean, default=True) relationship = db.relationship(FriendRelationshipType) from_owner = db.relationship(User, primaryjoin=(owner_id == User.id), backref='to_relations') to_friend = db.relationship(User, primaryjoin=(friend_id == User.id), backref='from_relations')
class Event(db.Model): __tablename__ = 'event' id = db.Column(db.String, primary_key=True) name = db.Column(db.String, nullable=False) description = db.Column(db.String, nullable=False) start_time = db.Column(db.DateTime, nullable=False) user_id = db.Column(db.String, db.ForeignKey('user.id'))
class Comment(db.Model): __tablename__ = 'comment' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.String, db.ForeignKey('user.id')) subject = db.Column(db.String, nullable=False) feedback = db.Column(db.String, nullable=False) created = db.Column(db.DateTime, default=db.func.now()) is_contacted = db.Column(db.String, nullable=False)
class Post(db.Model): __tablename__ = 'post' id = db.Column(db.String, primary_key=True) story = db.Column(db.String, nullable=False) created = db.Column(db.DateTime, nullable=False) user_id = db.Column(db.String, db.ForeignKey('user.id'))
class AuthToken(db.Model): id = db.Column(db.Integer, primary_key=True) token = db.Column(db.String(128), unique=False, nullable=False) expiration = db.Column(db.DateTime, default=(datetime.now() + timedelta(minutes=15))) user_id = db.Column(db.String, db.ForeignKey('user.id'))
from app.config.config import db from sqlalchemy.orm.exc import NoResultFound user_categories = db.Table( 'user_categories', db.Column("user_id", db.String, db.ForeignKey("user.id")), db.Column("category_id", db.Integer, db.ForeignKey("category.id"))) class Category(db.Model): __tablename__ = 'category' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(255), nullable=False, unique=True) user_products = db.relationship("UserProduct", back_populates="category") class CategoryActions: model = Category @classmethod def filter(cls, user, **kwargs): if 'id' in kwargs and kwargs['id'] is not None: return cls.model.query.filter_by(id=kwargs['id']).all() else: return cls.model.query.all() @classmethod def find_all(cls): return cls.model.query.all() @classmethod
class UserEmail(db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(256), unique=True, nullable=False) confirmed_at = db.Column(db.DateTime, default=datetime.now()) user_id = db.Column(db.String, db.ForeignKey('user.id'))