class Order(db.Model): id = db.Column(db.Integer, primary_key=True) item_ID = db.Column(db.ForeignKey('Item.id')) user_ID = db.Column(db.ForeignKey('User.id')) status = db.Column(db.String, nullable=False, default='W trakcie realizacji') item = db.relationship('Item', backref="user_associations") user = db.relationship('User', backref="item_associations") def __repr__(self): return f"Order('{self.id}', {self.item_ID}', '{self.user_ID}')"
class Comment(db.Model): id = db.Column(db.Integer, primary_key=True) content = db.Column(db.Text, nullable=False) date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) # The author of the comment author = db.Column(db.String(100), db.ForeignKey('user.username'), nullable=False) # The post under which the comment was written post_id = db.Column(db.Integer, db.ForeignKey('post.id'), nullable=False) def __repr__(self): return f'<Comment: id={self.id}, content={self.content[0:20]}>'
class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(100), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False) # Relationship to post model # lazy means sqlalchemy will load all of the data in one go posts = db.relationship('Post', backref='post_author', lazy=True, order_by='Post.date.desc()') def __repr__(self): return f'<User: id={self.id}, name={self.username}>'
class User(db.Model, UserMixin): __tablename__ = 'User' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False) image_file = db.Column(db.String(20), nullable=False, default='defaultpp.jpg') adress = db.Column(db.String(200)) phone = db.Column(db.String(20)) is_admin = db.Column(db.Boolean, default=False) def __repr__(self): return f"User('{self.username}', '{self.email}')"
class Item(db.Model): __tablename__ = 'Item' id = db.Column(db.Integer, primary_key=True) item_name = db.Column(db.String(30), unique=True, nullable=False) item_main_description = db.Column(db.String(30)) item_points_description = db.Column(db.String(200)) item_image = db.Column(db.String(30), nullable=False) item_price = db.Column(db.Float, nullable=False) def __repr__(self): return f"Item('{self.item_name}')"
class Item(db.Model): __tablename__ = 'Item' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30), unique=True, nullable=False) short_description = db.Column(db.String(30)) detailed_description = db.Column(db.String(200)) image = db.Column(db.String(30), nullable=False) price = db.Column(db.Float, nullable=False) def __repr__(self): return f"Item('{self.name}')"
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) content = db.Column(db.Text, nullable=False) date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) image_path = db.Column(db.String(200)) # user.id is lowercase because referencing the table name, which is user by default author = db.Column(db.String(100), db.ForeignKey('user.username'), nullable=False) comments = db.relationship('Comment', backref='post_src', lazy=True) def __repr__(self): return f'<Post: id={self.id}, title={self.title} author={self.author}>'