class Order(db.Model): __tablename__ = 'orders' id = db.Column(db.BigInteger, primary_key=True) description = db.Column(db.Text) status = db.Column(db.String(64),default=OrderStatus.UNPAID) discount_status = db.Column(db.String(64),default=OrderDiscountStatus.REGULAR) total = db.Column(db.Integer,nullable=False) total_cost = db.Column(db.DECIMAL(precision=20, scale=4), nullable=False) total_discount = db.Column(db.DECIMAL(precision=20, scale=4), nullable=False) user_id = db.Column(db.BigInteger, db.ForeignKey('users.id')) user = db.relationship('User') item_id = db.Column(db.BigInteger, db.ForeignKey('items.id')) item = db.relationship('Item') shipmet = db.relationship('Shipment') payment_id = db.Column(db.BigInteger,db.ForeignKey('payments.id')) payment = db.relationship('Payment',cascade="all,delete",backref="orders") created = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False) updated = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False, onupdate=datetime.datetime.now) def __str__(self): return "کاربر : "+str(self.user) +" - محصول : "+ str(self.item) + " - تعداد : " + str(self.total)
class Payment(db.Model): __tablename__ = 'payments' id = db.Column(db.Integer, primary_key=True) GUID = db.Column(db.String(128), default=random.randint(100000000000, 10000000000000000)) reference_id = db.Column(db.String(255), default=random.randint(100000000000, 10000000000000000)) amount = db.Column(db.DECIMAL(precision=20, scale=4), nullable=False) discount = db.Column(db.DECIMAL(precision=20, scale=4), nullable=False) type = db.Column(db.String(64), default=PaymentType.NOTITLE) status = db.Column(db.String(64), default=PaymentStatus.UNPAID) sequence = db.Column(db.String(255), nullable=False, default=PaymentStatus.UNPAID) details = db.Column(db.Text) # payment_method_id = db.Column(db.BigInteger,db.ForeignKey('payment_methods.id'),nullable=False) # payment_method = db.relationship('PaymentMethod') # orders = db.relationship('Order' , secondary = 'payment_orders', back_populates='payments') # sale_order_id = db.Column(db.String(255)) # sale_refrence_id = db.Column(db.String(255)) user_id = db.Column(db.BigInteger, db.ForeignKey('users.id')) user = db.relationship('User') # shipment = db.relationship('Shipment') messages = db.relationship('PaymentMessage', secondary='payment_message_payments', back_populates='payments') created = db.Column(db.TIMESTAMP, default=datetime.now, nullable=False) updated = db.Column(db.TIMESTAMP, default=datetime.now, nullable=False, onupdate=datetime.now) def __str__(self): return " پرداخت به کد رهگیری : " + str( self.GUID) + " باوضعیت :" + str( self.status) + " در تاریخ : " + str(self.created) def __init__(self): random.seed(datetime.now()) self.GUID = random.randint(100000000000, 10000000000000000) self.reference_id = random.randint(10000000000, 100000000000000000)
class Weather(db.Model): __tablename__ = 'record' id = db.Column(db.Integer, primary_key=True) city = db.Column(db.String(100), nullable=False) temp = db.Column(db.DECIMAL(5, 2), nullable=False) humidity = db.Column(db.Integer, nullable=False) addtime = db.Column(db.Integer, nullable=False, index=True) def __init__(self, city, temp, humidity): self.city = city self.temp = temp self.humidity = humidity self.addtime = int(time()) def __str__(self): return '<City %s> temp:%s' % (self.city, self.temp) def toJSON(self): return { 'id': self.id, 'city': self.city, 'temp': float(self.temp), 'humidity': self.humidity, 'addtime': self.addtime }
class ItemGaranty(db.Model): __tablename__ = 'item_garanties' id = db.Column(db.BigInteger, primary_key=True) price = db.Column(db.DECIMAL(precision=20, scale=4), nullable=False) item_id = db.Column(db.BigInteger, db.ForeignKey('items.id')) item = db.relationship('Item', cascade="all,delete") garanty_id = db.Column(db.BigInteger, db.ForeignKey('garanties.id')) garanty = db.relationship('Garanty', cascade="all,delete") created = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False) updated = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False, onupdate=datetime.datetime.now) def __str__(self): try: return "گارانتی محصول" + self.item.title + " گارانتی " + self.garanty.title + "باهزینه " + self.price except Exception as e: return "بدون عنوان"
class ALSRecommend(db.Model): """ALSRecommend model""" __tablename__ = 'tbl_als_recommend' id = db.Column(db.Integer, primary_key=True, unique=True) user_id = db.Column(db.String) food_id = db.Column(db.Integer) rating = db.Column(db.DECIMAL(asdecimal=False))
class Store(db.Model): """Store model""" __tablename__ = 'tbl_store' id = db.Column(db.Integer, unique=True, primary_key=True) restaurant_id = db.Column(db.Integer) food_name = db.Column(db.String(500)) address = db.Column(db.String(500)) category = db.Column(db.String(100)) id_food_category = db.Column(db.Integer, nullable=True) latitude = db.Column(db.DECIMAL(asdecimal=False)) longitude = db.Column(db.DECIMAL(asdecimal=False)) worktime = db.Column(db.String(20), nullable=True) rate = db.Column(db.DECIMAL(asdecimal=False), nullable=True) menu = db.Column(db.String(500), default='Menu trống') image_path = db.Column(db.String(500), nullable=True) totalreview = db.Column(db.Integer, default=0) view = db.Column(db.Integer, default=0)
class CreditLog(db.Model): __tablename__ = 'user_credit_logs' id = db.Column(db.BigInteger, primary_key=True) before_credit = db.Column(db.DECIMAL(precision=20, scale=4), nullable=False) after_credit = db.Column(db.DECIMAL(precision=20, scale=4), nullable=False) user_id = db.Column(db.BigInteger, db.ForeignKey('users.id')) user = db.relationship('User') created = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False) updated = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False, onupdate=datetime.datetime.now)
class Food(db.Model): """Food model""" __tablename__ = 'tbl_food' id = db.Column(db.Integer, unique=True, primary_key=True) restaurant_id = db.Column(db.Integer) food_id = db.Column(db.Integer, unique=True) name = db.Column(db.String(100)) price = db.Column(db.Integer) image = db.Column(db.String(200)) average_score = db.Column(db.DECIMAL(asdecimal=False), nullable=True) total_vote = db.Column(db.Integer, nullable=True) total_view = db.Column(db.Integer, nullable=True) created_time = db.Column(db.DateTime, default=datetime.datetime.now) updated_time = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)
class Insurance(db.Model): __tablename__ = "insurances" id = db.Column(db.BigInteger, primary_key=True) company = db.Column(db.String(length=100), nullable=False) description = db.Column(db.Text, nullable=False) price = db.Column(db.DECIMAL(precision=20, scale=4), nullable=False) shipments = db.relationship('Shipment') created = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False) updated = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False, onupdate=datetime.datetime.now) def __str__(self): return self.company
class Coin(db.Model): __tablename__ = 'coins' id = db.Column(db.BigInteger, primary_key=True) title = db.Column(db.String(length=255), nullable=False) description = db.Column(db.Text, nullable=False) type = db.Column(db.String(64), nullable=False, default=CoinType.FORSALE) quantity = db.Column(db.Integer(), default=0, nullable=False) price = db.Column(db.DECIMAL(precision=20, scale=4), default=0) created = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False) updated = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False, onupdate=datetime.datetime.now) def __str__(self): return self.title + " به تعداد " + str( self.quantity) + " از نوع " + self.type
class Item(db.Model): __tablename__ = 'items' id = db.Column(db.BigInteger, primary_key=True) title = db.Column(db.String(length=100), nullable=False) description = db.Column(db.Text(),nullable=False) price = db.Column(db.DECIMAL(precision=20, scale=4), nullable=False) quantity = db.Column(db.Integer(),default=0,nullable=False) discount = db.Column(db.Integer(),default=0,nullable=False) details = db.Column(db.Text()) images = db.Column(db.Text, nullable=False) product_id = db.Column(db.BigInteger, db.ForeignKey('products.id'),nullable=False) product = db.relationship('Product') orders = db.relationship('Order') created = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False) updated = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False, onupdate=datetime.datetime.now) def __str__(self): return " محصول :"+str(self.product.title) + " آیتم: " + self.title
class Bid(db.Model): __tablename__ = 'bids' id = db.Column(db.BigInteger, primary_key=True) bid_price = db.Column(db.DECIMAL(precision=20, scale=4), nullable=False) current_bids = db.Column(db.Integer, nullable=False) won = db.Column(db.Boolean, default=False) user_plan_id = db.Column(db.BigInteger, db.ForeignKey('user_plans.id')) user_plan = db.relationship('UserPlan') auction_id = db.Column(db.BigInteger, db.ForeignKey('auctions.id')) auction = db.relationship('Auction') created = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False) updated = db.Column(db.TIMESTAMP, default=datetime.datetime.now, onupdate=datetime.datetime.now)
class Coupon(db.Model): __tablename__ = 'coupons' id = db.Column(db.BigInteger, primary_key=True) title = db.Column(db.String(length=100), nullable=False) description = db.Column(db.Text, nullable=False) amount = db.Column(db.DECIMAL(precision=20, scale=4), nullable=False) expired = db.Column(db.Boolean, default=False) type = db.Column(db.String(64), default=CouponType.SYSTEM) users = db.relationship('User', secondary='user_coupons', back_populates='coupons', lazy='dynamic') created = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False) updated = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False, onupdate=datetime.datetime.now) def __str__(self): return self.title
class Auction(db.Model): __tablename__ = 'auctions' id = db.Column(db.BigInteger, primary_key=True) title = db.Column(db.String(255), nullable=False) image = db.Column(db.Text) tag = db.Column(db.String(255)) description = db.Column(db.Text, nullable=False) is_active = db.Column(db.Boolean, nullable=False, default=True) done = db.Column(db.Boolean, default=False) start_date = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False) base_price = db.Column(db.DECIMAL(precision=20, scale=4), nullable=False) max_price = db.Column(db.DECIMAL(precision=20, scale=4), nullable=False) max_members = db.Column(db.BigInteger, default=10, nullable=False) min_members = db.Column(db.BigInteger, default=0, nullable=False) ratio = db.Column(db.Integer, default=1, nullable=False) have_extra_gems = db.Column(db.Boolean, nullable=False, default=False) extra_bids = db.Column(db.Integer, default=0, nullable=False) required_gems = db.Column(db.Integer, default=0, nullable=False) target_bid = db.Column(db.Integer, default=3) item_id = db.Column(db.BigInteger, db.ForeignKey('items.id'), nullable=False) item = db.relationship('Item') participants = db.relationship('User', secondary='user_auction_participations', lazy='dynamic', back_populates='auctions') views = db.relationship('User', secondary='user_auction_views', lazy='dynamic', back_populates='auction_views') likes = db.relationship('User', secondary='user_auction_likes', lazy='dynamic', back_populates='auction_likes') level_id = db.Column(db.BigInteger, db.ForeignKey('levels.id')) level = db.relationship('Level') advertisement_id = db.Column(db.BigInteger, db.ForeignKey('advertisements.id')) advertisement = db.relationship('Advertisement') charity_id = db.Column(db.BigInteger, db.ForeignKey('charities.id')) charity = db.relationship('Charity') plans = db.relationship('AuctionPlan', lazy='dynamic') created = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False) updated = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False, onupdate=datetime.datetime.now) def __str__(self): return self.title