class Order(BaseModel, db.Model): __tablename__ = 'ihome_order' id = db.Column(db.Integer, primary_key=True) # 外键关联用户, 一个用户对应多个订单 user_id = db.Column(db.Integer, db.ForeignKey('ihome_user.id'), nullable=False) # 一个房子对应多个订单 house_id = db.Column(db.Integer, db.ForeignKey('ihome_house.id'), nullable=False) # 订单的创建时间 begin_date = db.Column(db.DateTime, nullable=False) # 订单的结束时间 end_date = db.Column(db.DateTime, nullable=False) # 订单生效的天数 days = db.Column(db.Integer, nullable=False) # 房间的价格 house_price = db.Column(db.Integer, nullable=False) # 房间的数量 amount = db.Column(db.Integer, nullable=False) # 订单的状态,使用了枚举法, index 等于 true 意思是 默认开启了下标索引, WAIT_ACCEPT相当于0, 可以使用时可以用0代替 status = db.Column( db.Enum( # 待接单 'WAIT_ACCEPT', # 待支付 'WAIT_PAYMENT', # 已支付 'PAID', # 待评价 'WAIT_COMMENT', # 已完成 'COMPLETE', # 已取消 'CANCELED', # 已拒单 'REJECTED'), default='WAIT_ACCEPT', index=True) # 订单评价 comment = db.Column(db.Text) # 把订单对象初始化如下的字典形式 def to_dict(self): return { 'order_id': self.id, 'house_title': self.house.title, 'image': self.house.index_image_url if self.house.index_image_url else '', 'create_date': self.create_time.strftime('%Y-%m-%d'), 'begin_date': self.begin_date.strftime('%Y-%m-%d'), 'end_date': self.end_date.strftime('%Y-%m-%d'), 'amount': self.amount, 'days': self.days, 'status': self.status, 'comment': self.comment }
class Order(BaseModel, db.Model): ''' ''' __tablename__ = 'ihome_order' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('ihome_user.id'), nullable=False) house_id = db.Column(db.Integer, db.ForeignKey('ihome_house.id'), nullable=False) begin_date = db.Column(db.DateTime, nullable=False) end_date = db.Column(db.DateTime, nullable=False) days = db.Column(db.Integer, nullable=False) house_price = db.Column(db.Integer, nullable=False) amount = db.Column(db.Integer, nullable=False) status = db.Column( db.Enum( 'WAIT_ACCEPT', # 待接单 'WAIT_PAYMENT', # 待支付 'PAID', # 已支付 'WAIT_COMMENT', # 待评价 'COMPLETE', # 已完成 'CANCELED', # 已取消 'REJECTED' # 已拒单 ), default='WAIT_ACCEPT', index=True) comment = db.Column(db.Text) def to_dict(self): return { 'order_id': self.id, 'house_title': self.house.title, 'image': self.house.index_image_url if self.house.index_image_url else '', 'create_date': self.create_time.strftime('%Y-%m-%d'), 'begin_date': self.begin_date.strftime('%Y-%m-%d'), 'end_date': self.end_date.strftime('%Y-%m-%d'), 'amount': self.amount, 'days': self.days, 'status': self.status, 'comment': self.comment }
class Order(BaseModel, db.Model): __tablename__ = "ihome_order" id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey("ihome_user.id"), nullable=False) house_id = db.Column(db.Integer, db.ForeignKey('ihome_house.id'), nullable=False) begin_date = db.Column(db.DATETIME, nullable=False) end_date = db.Column(db.DATETIME, nullable=False) days = db.Column(db.Integer, nullable=False) house_price = db.Column(db.Integer, nullable=False) amount = db.Column(db.Integer, nullable=False) # 总的价格 status = db.Column( db.Enum( "WAIT_ACCEPT", # 待接单 "WAIT_PAYMENT", # 代付款 "PAID", # 已支付 "WAIT_COMMENT", # 待评价 "COMPLETE", # 已完成 "CANCELED", # 已取消 "REJECTED" # 已拒单 ), default="WAIT_ACCEPT", index=True) comment = db.Column(db.Text) def to_dict(self): return { 'order_id': self.id, 'house_title': self.house.title, 'image': self.house.index_image_url if self.house.index_image_url else "", 'create_date': self.create_time.strftime('%Y-%m-%d'), 'begin_date': self.begin_date.strftime('%Y-%m-%d'), 'end_date': self.end_date.strftime('%Y-%m-%d'), 'amount': self.amount, 'days': self.days, 'status': self.status, 'comment': self.comment }
class Order(BaseModel, db.Model): # 订单 __tablename__ = "order" id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey("customer.id"), nullable=False) # 客户id goods_id = db.Column(db.Integer, db.ForeignKey("goods.id"), nullable=False) # 商品id goods_price = db.Column(db.Integer, nullable=False) # 商品价格 amount = db.Column(db.Integer, nullable=False) # 总价格 note = db.Column(db.String(200), nullable=True) # 备注 status = db.Column(db.Enum(*ORDER_ENUM.keys()), default="WAIT_ACCEPT", index=True) comment = db.Column(db.Text) # 评论 Goods = db.relationship("Goods", secondary=goodscomments_goods_order) GoodsComments = db.relationship("GoodsComments", secondary=goodscomments_goods_order)