Selaa lähdekoodia

增加query分组

chenjunkai 6 vuotta sitten
vanhempi
commit
2f5ba375d8
1 muutettua tiedostoa jossa 18 lisäystä ja 1 poistoa
  1. 18 1
      Controller/MealManage.py

+ 18 - 1
Controller/MealManage.py

@@ -230,12 +230,28 @@ class MealView(View):
         response.lang = tko.lang
         if tko.code != 0:
             return response.json(tko.code)
-        userID = tko.userID
         if operation == 'list':
             return self.do_query_list(response)
+        elif operation == 'query':
+            return self.do_query(response)
         else:
             return response.json(414)
 
+    def do_query(self, response):
+        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)
+            return response.json(0,res)
+        else:
+            return response.json(0, [])
+
     def do_query_list(self, response):
         qs = Store_Meal.objects.all().values("id", "title", "content", "price", "day", "currency","bucket__storeDay",
                                              "bucket__bucket")
@@ -244,3 +260,4 @@ class MealView(View):
             return response.json(0, list(qs))
         else:
             return response.json(0, [])
+