Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ECE651_Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chris Li
ECE651_Backend
Commits
f1eb239a
Commit
f1eb239a
authored
2 years ago
by
Yirou Qiu
Browse files
Options
Downloads
Patches
Plain Diff
Added an api for searching the sum of price in different categories
parent
b2db7fe2
No related branches found
No related tags found
1 merge request
!8
Yrq/feature/bill sum price
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
core/api/billPriceSum.py
+44
-0
44 additions, 0 deletions
core/api/billPriceSum.py
core/api/billSearch.py
+0
-1
0 additions, 1 deletion
core/api/billSearch.py
core/models/bill.py
+0
-13
0 additions, 13 deletions
core/models/bill.py
core/urls.py
+5
-1
5 additions, 1 deletion
core/urls.py
with
49 additions
and
15 deletions
core/api/billPriceSum.py
0 → 100644
+
44
−
0
View file @
f1eb239a
from
rest_framework
import
generics
,
response
from
core.models.bill
import
Bill
,
BillSearchQuerySet
from
core.serializers.bill
import
BillSerializer
from
rest_framework
import
authentication
from
django.db.models
import
Sum
class
BillSumPriceListView
(
generics
.
ListAPIView
):
queryset
=
Bill
.
objects
.
all
()
serializer_class
=
BillSerializer
authentication_classes
=
[
authentication
.
SessionAuthentication
,
authentication
.
TokenAuthentication
]
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
categorieModel
=
{
1
:
"
Food
"
,
2
:
"
Groceries
"
,
3
:
"
Transportation
"
,
4
:
"
clothing
"
,
5
:
"
Entertainment
"
,
6
:
"
Bill
"
,
7
:
"
Sports
"
,
8
:
"
Electronics
"
,
9
:
"
Travel
"
,
10
:
"
House & Car
"
,
11
:
"
Others
"
,
}
queryset
=
self
.
filter_queryset
(
self
.
get_queryset
())
user
=
None
if
self
.
request
.
user
.
is_authenticated
:
user
=
self
.
request
.
user
data
=
{}
for
i
in
range
(
1
,
12
):
qs
=
BillSearchQuerySet
(
Bill
).
searchCategories
(
query
=
i
,
user
=
user
)
total_price
=
qs
.
aggregate
(
Sum
(
'
price
'
))
print
(
total_price
)
data
[
categorieModel
[
i
]]
=
total_price
[
'
price__sum
'
]
print
(
data
)
return
response
.
Response
(
data
)
BillSumPriceListViewAPI
=
BillSumPriceListView
.
as_view
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
core/api/billSearch.py
+
0
−
1
View file @
f1eb239a
...
...
@@ -35,5 +35,4 @@ class SearchBillListView(generics.ListAPIView):
result
=
qs
.
searchToday
(
user
=
user
)
elif
item
==
"
title
"
:
result
=
qs
.
searchTitle
(
keyword
,
user
=
user
)
print
(
result
)
return
result
\ No newline at end of file
This diff is collapsed.
Click to expand it.
core/models/bill.py
+
0
−
13
View file @
f1eb239a
...
...
@@ -41,20 +41,7 @@ class BillSearchQuerySet(models.QuerySet):
if
user
is
not
None
:
qs
=
self
.
filter
(
user
=
user
).
filter
(
lookup
)
return
qs
# def searchTitle(self, keyword, user=None):
# lookup = Q(title__contains = keyword)
# qs = self.filter(lookup)
# if user is not None:
# qs = self.filter(user=user).filter(lookup)
# return qs
# def categorieAmount(self, date, categories, user=None):
# if date == "day":
# qs = self.searchCategories(categories, user=user).searchToday(user=user)
# elif date == "month":
# qs = self.searchCategories(categories, user=user).searchThisMonth(user=user)
class
BillManager
(
models
.
Manager
):
...
...
This diff is collapsed.
Click to expand it.
core/urls.py
+
5
−
1
View file @
f1eb239a
...
...
@@ -8,6 +8,7 @@ from core.api.profile import ProfileViewSet
from
core.api.coupon
import
CouponViewSet
from
core.api.bill
import
*
from
core.api.billSearch
import
SearchBillListView
from
core.api.billPriceSum
import
BillSumPriceListViewAPI
router
=
routers
.
DefaultRouter
()
...
...
@@ -36,7 +37,10 @@ urlpatterns += [
path
(
'
api/bill/<uuid:pk>/
'
,
bill_detail_api
,
name
=
"
bill-detail
"
),
# bill search
path
(
'
api/bill/search/
'
,
SearchBillListView
.
as_view
(),
name
=
"
bill-search
"
)
path
(
'
api/bill/search/
'
,
SearchBillListView
.
as_view
(),
name
=
"
bill-search
"
),
# bill price list searched by categories
path
(
'
api/bill/price-sum/
'
,
BillSumPriceListViewAPI
,
name
=
"
bill-price-sum
"
)
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment