class ProductModel(BasicModel): class Meta: behaviors = (Searchable, ) label_name = { "title": u"商品名稱", "spec": u"商品規格", "image_url": u"圖片網址", "quantity": u"庫存數量", "date": u"可購買期限", "price": u"價格", "limit_1": u"已出售數量", "limit_2": u"可供購買數量", } title = Fields.StringProperty(default=u"未命名的商品") spec = Fields.StringProperty(default=u"") image_url = Fields.StringProperty(default=u"") date = Fields.DateTimeProperty() price = Fields.FloatProperty(default=0.0) limit_1 = Fields.IntegerProperty(default=0) limit_2 = Fields.IntegerProperty(default=99999) store = Fields.CategoryProperty(kind=StoreModel) group_info = Fields.CategoryProperty(kind=GroupInfoModel) @classmethod def get_by_feature(cls, store, group_info, title, spec, price): p = float(price) return cls.query(cls.title == title, cls.spec == spec, cls.price == p, cls.store == store, cls.group_info == group_info).get()
class OrderDetailModel(BasicModel): class Meta: behaviors = (Searchable, ) label_name = { "title": u"訂購方式", "order_info": u"所屬訂單", } title = Fields.StringProperty(default=u"") order_info = Fields.CategoryProperty(kind=OrderInfoModel) group_info = Fields.CategoryProperty(kind=GroupInfoModel) shipping_fee = Fields.FloatProperty() sum = Fields.FloatProperty() def items(self): from order_item import OrderItemModel return OrderItemModel.query(OrderItemModel.order_detail == self.key ).order(-OrderItemModel.sort).fetch()