Commit 3321e310 authored by Libcat's avatar Libcat 👷
Browse files

产品查询适配自选功能

parent 1df23fb4
......@@ -11,13 +11,20 @@ router = APIRouter(tags=["产品CRUD"], prefix="/products")
@router.get('/', response_model=List[api.ProductGet], description="获取产品列表")
async def get_list(product_type: Optional[int] = None,
async def get_list(category: Optional[int] = None,
categoryName: Optional[str] = None,
name: Optional[str] = None):
q = Product.select()
if product_type:
q = q.where(Product.product_type_id == product_type)
q = Product.select(Product, Category).join(Category)
if categoryName:
q = q.where(Category.name == categoryName)
if category:
q = q.where(Product.category.id == category)
if name:
q = q.where(Product.name.contains(name))
return list(q)
......
......@@ -37,7 +37,13 @@ with dbconnection.atomic():
Category.create(name='关于亲情')
Category.create(name='多肉绿植')
Category.create(name='花束自选')
Category.create(name='插花自选')
Category.create(name='主花', flexi=True)
Category.create(name='配花', flexi=True)
Category.create(name='配草', flexi=True)
Category.create(name='包装', flexi=True)
Category.create(name='丝带', flexi=True)
Product.create(
name="红玫瑰",
price=9.9,
......
......@@ -30,7 +30,10 @@ async def add_process_time_header(request: Request, call_next):
db.close()
return response
import logging
logger = logging.getLogger('peewee')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
app.include_router(api_users.router)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment