From 80ce1cc6623b4739121c363851558388152b9613 Mon Sep 17 00:00:00 2001 From: kian Date: Sat, 21 Oct 2023 00:42:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=99=A2=E6=A0=A1=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=9D=A1=E4=BB=B6=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/post/views.py | 4 ---- apps/school/views.py | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/post/views.py b/apps/post/views.py index 53aa39a..206cf2b 100644 --- a/apps/post/views.py +++ b/apps/post/views.py @@ -274,13 +274,9 @@ def manage_post(request, post_id): elif request.method == 'POST': body = json.loads(request.body) record_serializer = GISourceSerializer(record, data=body) - logger.error('1') if record_serializer.is_valid(): - logger.error('2') record_serializer.save() - logger.error('3') return JsonResponse({"code": 0, "msg": "success"}) - logger.error('4') logger.error(record_serializer.errors) return JsonResponse({"code": 500, "msg": 'record_serializer not pass'}) elif request.method == 'DELETE': diff --git a/apps/school/views.py b/apps/school/views.py index 3a4a40f..13fc658 100644 --- a/apps/school/views.py +++ b/apps/school/views.py @@ -16,6 +16,20 @@ @permission_classes((AllowAny,)) @authentication_classes((TokenAuthentication,)) def get_school_list(request): + """ + e.g. + http://127.0.0.1:8000/api/schools + http://127.0.0.1:8000/api/schools?tag=Urban_Planning + http://127.0.0.1:8000/api/schools?tag=Urban_Planning,Transportation + """ + whereSql = '' + # 如果请求中带了 tag 参数,则用 tag 参数去构造 WHERE 条件 + if 'tag' in request.GET: + tags = request.GET['tag'].split(',') + whereArr = [] + for tag in tags: + whereArr.append('(u.' + tag + '=1 AND p.' + tag + '=1)') + whereSql = 'WHERE' + ' OR '.join(whereArr) with connection.cursor() as cursor: cursor.execute(""" SELECT u.University_Name_CN, u.University_Name_EN, u.University_Name_Local, @@ -29,7 +43,7 @@ def get_school_list(request): LEFT JOIN new_city c ON u.City = c.City_Name_EN LEFT JOIN new_country co ON c.Country = co.Country_Name_CN LEFT JOIN new_people p ON u.University_Name_EN = p.University - """) + """ + whereSql) rows = cursor.fetchall() data = []