|
@@ -12,7 +12,7 @@
|
|
|
@Contact: chanjunkai@163.com
|
|
|
"""
|
|
|
import traceback
|
|
|
-from django.db.models import Q, F
|
|
|
+
|
|
|
from django.utils import timezone
|
|
|
from django.utils.decorators import method_decorator
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
@@ -230,23 +230,21 @@ class MealView(View):
|
|
|
return response.json(414)
|
|
|
|
|
|
def do_query(self, response):
|
|
|
- qs = Store_Meal.objects.all().annotate(area=F("bucket__area")).values("id", "title", "content", "price", "day",
|
|
|
- "currency", "bucket__storeDay",
|
|
|
- "bucket__bucket", "bucket__area")
|
|
|
- print(qs)
|
|
|
- return response.json(0, list(qs))
|
|
|
+ qs = Store_Meal.objects.all().values("id", "title", "content", "price", "day", "currency", "bucket__storeDay",
|
|
|
+ "bucket__bucket", "bucket__area")
|
|
|
if qs.exists():
|
|
|
-
|
|
|
- res = {}
|
|
|
- for q in qs:
|
|
|
- if q['bucket__area'] not in res:
|
|
|
- res[q['bucket__area']] = []
|
|
|
- res[q['bucket__area']].append(q)
|
|
|
- # res['cloudpng'] = 'https://www.dvema.com/web/images/cloud_banner.png'
|
|
|
+ ql = list(qs)
|
|
|
+ from operator import itemgetter
|
|
|
+ from itertools import groupby
|
|
|
+ ql.sort(key=itemgetter('bucket__area'))
|
|
|
+ res = []
|
|
|
+ for area, items in groupby(ql, key=itemgetter('bucket__area')):
|
|
|
+ res_c = {'area': area, 'items': list(items)}
|
|
|
+ res.append(res_c)
|
|
|
result = {'meals': res, 'extra': {'cloud_banner': 'https://www.dvema.com/web/images/cloud_banner.png'}}
|
|
|
return response.json(0, result)
|
|
|
else:
|
|
|
- return response.json(0, [])
|
|
|
+ return response.json(0)
|
|
|
|
|
|
def do_query_list(self, response):
|
|
|
qs = Store_Meal.objects.all(). \
|