From bedff6d160c7ae5ca1846450b2adce27d31e9de9 Mon Sep 17 00:00:00 2001 From: BINGWU Date: Tue, 26 Mar 2024 00:41:33 +0800 Subject: [PATCH] pymongo --- .../models/__pycache__/user.cpython-311.pyc | Bin 677 -> 1234 bytes serve/serve/models/user.py | 14 +++++--- .../__pycache__/connectdb.cpython-311.pyc | Bin 0 -> 617 bytes .../utils/__pycache__/test.cpython-311.pyc | Bin 0 -> 1011 bytes serve/serve/utils/connectdb.py | 9 +++++ serve/serve/utils/test.py | 17 +++++++++ .../views/__pycache__/user.cpython-311.pyc | Bin 1138 -> 2900 bytes serve/serve/views/user.py | 34 +++++++++++++++++- 8 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 serve/serve/utils/__pycache__/connectdb.cpython-311.pyc create mode 100644 serve/serve/utils/__pycache__/test.cpython-311.pyc create mode 100644 serve/serve/utils/connectdb.py create mode 100644 serve/serve/utils/test.py diff --git a/serve/serve/models/__pycache__/user.cpython-311.pyc b/serve/serve/models/__pycache__/user.cpython-311.pyc index 0ab40215a48004a91e11676cfa8a6dc1629f80da..6d3eb20bbab6d4f9b674651a9f2f091af9de00da 100644 GIT binary patch literal 1234 zcmZ`&O-vI(6rR~_mu(AKr155?XeH^PhLZ9%NSoGvnB6Ci+~1#GB8Thb+4)@2AJ@Bkp`1wb;EwqyWy*&8%HBDe_Sq8Ogz zqDaYu%)l`pnvtnG?G~#xc6>T~-(JE9VbqH#%VlgKuNW>XK2qqM&M{*XV4y<;bV&kO zUX64IZZTuG>i|6}Sfv{{#||LK5|Zd(zPhxEi~b`QVJnwWscIOGX=B5nal^1(RJFK0 zXc$kcrWG)R*NGC`HkGOm9X|*UhT(kCCHONq<;nc=7)(zVX37>W z9DP0bxwC$>cW|`#vGC*5_Tm2P!~OL_rRJ}=P9KTwisjZY&X%2Jm)NFXcAczkI%Wy; zLT0_1=VQCzVX}rpWZ7fOD^ywRcBMuJ*uDaI#k?$odat)f(i`Kgk#uu};dp(%oxHJe z=iR+#GT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Y_x_2)eJ_45@EPnpl!>5dRN2s1I=ceJda6AOq1yrM`>|tQC?zh>Mf3f z#Ny)e{Gyb}tjr&|B!Jr4fw(w*5=(&I1s0i$EUs5rTraS=-sKjb!FQ2c{R+4G1s3(s zAZx0)L8j;@7o{eaq-t_aPUkf7DB=f7+~Q8jO3X{o*DEc`DK26IiWGqihS(Yp6kN$r zBnc7~2NJ(HY;yBcN^?@}isXS@kaLSm875nD8Bea`k~H|h#>%MifdNhkF|cwrxOB+Q X;JV17e1%2%12Yp3Qv(MGg3SZ~k~CWA diff --git a/serve/serve/views/user.py b/serve/serve/views/user.py index 0d11075..ab9448e 100644 --- a/serve/serve/views/user.py +++ b/serve/serve/views/user.py @@ -1,17 +1,49 @@ from django.shortcuts import render, HttpResponse from serve.models.user import UserModel +from django.http import JsonResponse import json from django.urls import path +from serve.utils.connectdb import connectdb +from bson.objectid import ObjectId + +collection = connectdb('user_model') def createUser(request): print(request.method) data = json.loads(request.body) print(data.get('name')) - UserModel.objects.create(username='154782456', password='123456') + UserModel.objects.create(username='154782456', password='123456', subjects=[ + { + 'subjectName': "语文", + 'subjectScore': 90 + }] + ) return HttpResponse("插入成功") +def deleteUser(request): + result = UserModel.objects.filter(id="ly").first().delete() + print(result) + return HttpResponse('删除成功') + + +def updateUser(request): + result = UserModel.objects.filter(id='1').first().update(username="ly") + return HttpResponse(result) + + +def getUser(request): + # user = UserModel.objects.get(id='660195d50d5cb377410134f7') + user = collection.find_one({'_id': ObjectId('660195d50d5cb377410134f7')}) + user['_id'] = str(user['_id']) + # 返回 JSON 响应 + return JsonResponse(user) + + user_url = [ path('user/create', createUser), + path('user/delete', deleteUser), + path('user/update', updateUser), + path('user/get', getUser), ]