| 123456789101112131415161718192021222324 |
- from db import MongoDao
- from data import BrandInfo, ProductInfo
- product_dao = MongoDao("vbrand-ec")
- class Service:
- @staticmethod
- def get_brand_list():
- """获取数据库中存储的品牌列表"""
- brand_list = product_dao.get_one_field_data("brandName")
- brand_list = list(dict.fromkeys(brand_list))
-
- return brand_list
-
- @staticmethod
- def load_products_by_brand(brand_name):
- """加载选定品牌的所有商品"""
- brand_info = BrandInfo(brand_name)
- return [product.title for product in brand_info.product_list], brand_info
- if __name__ == "__main__":
- brand_list = Service.get_brand_list()
- print(brand_list)
|