Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Libcat
wenyuan-backend
Commits
3321e310
Commit
3321e310
authored
May 28, 2021
by
Libcat
👷
Browse files
产品查询适配自选功能
parent
1df23fb4
Changes
6
Hide whitespace changes
Inline
Side-by-side
controllers/api_products.py
View file @
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
View file @
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
View file @
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
View file @
3321e310
903 KB
upload/product-1622178922.png
0 → 100644
View file @
3321e310
577 KB
upload/product-1622178938.png
0 → 100644
View file @
3321e310
893 KB
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment