class PartData(db.Model): __tablename__ = 'partdatas' id = db.Column(db.Integer, primary_key=True) ref_part = db.Column(db.String(255), nullable=False, unique=True, index=True) weight = db.Column(db.Integer, nullable=False) diameter = db.Column(db.Integer, nullable=True) dimension = db.Column(db.String(100), nullable=True) date_of_prod = db.Column(db.DateTime(), nullable=True) num_oem = db.Column(db.String(300), nullable=False, unique=True, index=True) country_of_origin = db.Column(db.String(80), nullable=False) volume_of_part = db.Column(db.Integer) product_id = db.Column(db.Integer, db.ForeignKey('products.id'), nullable=True) car_compatibilities = db.relationship(CarModel, secondary='car_part_compts', backref='partdatas', lazy=False) car_compt = db.Table('car_part_compts', db.Column('partdata_id', db.Integer, db.ForeignKey('partdatas.id')), db.Column('carmodel_id', db.Integer, db.ForeignKey('carmodels.id')))
__tablename__ = 'carmodels' id = db.Column(db.Integer, primary_key=True) designation = db.Column(db.String(300), unique=True, index=True, nullable=False) date_of_prod = db.Column(db.DateTime(), nullable=False) date_end_of_prod = db.Column(db.DateTime(), nullable=True) carbrand_id = db.Column(db.Integer, db.ForeignKey('carbrands.id'), nullable=False) type_id = db.Column(db.Integer, db.ForeignKey('cartypes.id'), nullable=False) # carbrand = db.relationship('CarBrand', foreign_keys=[carbrand_id], lazy='dynamic') type = db.relationship('CarType', foreign_keys=[type_id], lazy=False) class CarType(db.Model): __tablename__ = 'cartypes' id = db.Column(db.Integer, primary_key=True) designation = db.Column(db.String(80), unique=True) carbrand_types = \ db.Table('carbrand_types', db.Column('carbran_id', db.Integer, db.ForeignKey('carbrands.id')), db.Column('cartype_id', db.Integer, db.ForeignKey('cartypes.id')))
from app.factory import db class WishList(db.Model): __tablename__ = 'wishlists' id = db.Column(db.Integer, primary_key=True) user_id = db.Column('User', db.Integer, db.ForeignKey('users.id'), nullable=False) product = db.relationship('Product', secondary='wishlistitems', lazy=False) wishListItem = db.Table( 'wishlistitems', db.Model.metadata, db.Column('wishlist_id', db.Integer, db.ForeignKey('wishlists.id')), db.Column('product_id', db.Integer, db.ForeignKey('products.id')))
name = db.Column(db.String(255)) slug = db.Column(db.String(255), index=True, unique=True) description = db.Column(db.String(300)) created_at = db.Column(db.DateTime(), default=datetime.utcnow(), index=True) updated_at = db.Column(db.DateTime()) def get_summary(self): return { 'id': self.id, 'name': self.name, 'description': self.description, 'image_urls': [image.file_path.replace('\\', '/') for image in self.images] } def __repr__(self): return self.name def slug_generator_for_category(self, name): self.slug = 'catg-0'+str(random.randint(0, 100))+str(randomString(6))+'-'+str(name) """ @event.listens_for(Category.name, 'set') def receive_set(target, value, oldvalue, initiator): target.slug = slugify(unicode(value)) """ products_categories = \ db.Table("products_categories", db.Column("category_id", db.Integer, db.ForeignKey("categories.id")), db.Column("product_id", db.Integer, db.ForeignKey("products.id")))
name = db.Column(db.String(80), unique=True, nullable=False) description = db.Column(db.String(100), nullable=True) class UserRole(db.Model): __tablename__ = 'users_roles' user_id = db.Column(db.Integer, db.ForeignKey("users.id")) role_id = db.Column(db.Integer, db.ForeignKey("roles.id")) # users = db.relationship("User", foreign_keys=[user_id], backref='roles') user = db.relationship("User", foreign_keys=[user_id], backref='users_roles') role = db.relationship("Role", foreign_keys=[role_id], backref='users_roles') created_at = db.Column(db.DateTime(), nullable=False, default=datetime.utcnow) __mapper_args__ = {'primary_key': [user_id, role_id]} users_roles = db.Table('users_roles', db.Column('user_id', db.Integer, db.ForeignKey('users.id')), db.Column('role_id', db.Integer, db.ForeignKey('roles.id')), keep_existing=True)