Skip to content
GitLab
菜单
项目
群组
代码片段
/
帮助
帮助
支持
社区论坛
快捷键
?
提交反馈
登录/注册
切换导航
菜单
打开侧边栏
Libcat
wenyuan-backend
提交
3321e310
提交
3321e310
编辑于
5月 28, 2021
作者:
Libcat
👷
浏览文件
产品查询适配自选功能
上级
1df23fb4
变更
6
Show whitespace changes
Inline
Side-by-side
controllers/api_products.py
浏览文件 @
3321e310
...
...
@@ -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
)
...
...
init.py
浏览文件 @
3321e310
...
...
@@ -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
,
...
...
main.py
浏览文件 @
3321e310
...
...
@@ -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
)
...
...
upload/product-1622178906.png
0 → 100644
浏览文件 @
3321e310
903.2 KB
upload/product-1622178922.png
0 → 100644
浏览文件 @
3321e310
576.7 KB
upload/product-1622178938.png
0 → 100644
浏览文件 @
3321e310
892.9 KB
编辑
预览
支持
Markdown
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录