From b2088291df3f20d6c80473f105955950f934935a Mon Sep 17 00:00:00 2001 From: Rupika Date: Wed, 13 Feb 2019 17:06:58 -0800 Subject: [PATCH] successfully updates section from the request.data -- dummy JSON in postman --- back/backend/views.py | 45 +----------------------------------------- back/db.sqlite3 | Bin 105472 -> 105472 bytes 2 files changed, 1 insertion(+), 44 deletions(-) diff --git a/back/backend/views.py b/back/backend/views.py index f180169..8cf55ae 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -3,7 +3,6 @@ from django.http import JsonResponse from .models import * from .policy import pol import os -# import json # function that prints all the reports @@ -156,49 +155,7 @@ def report_detail(request, report_pk): # update a section with new data @api_view(['PUT']) def section(request, report_pk, section_pk): - json_input = { - "fields": [ - { - "id": 178, - "value": "2016-05-22", - "type": "date" - }, - { - "id": 179, - "value": "2016-05-22", - "type": "date" - }, - { - "id": 180, - "value": 3.14, - "type": "decimal" - }, - { - "id": 181, - "value": 10000, - "type": "integer" - }, - { - "id": 182, - "value": True, - "type": "boolean" - }, - ] -} - - ''' - 1) decode JSON object into dictionaries - 2) iterate through fields (for loop)? - 3) in each iteration, check for data type - 4) in the datatype, update the database - 4a) update = field_set.get(id=request.data.id) - 4b) update.data_type = request.data["value"] - ''' - - # print("request data: {}".format(type(request.body))) - # json.loads() - - for v in json_input["fields"]: + for v in request.data["fields"]: update_field = Field.objects.get(id=v["id"]) if v["type"] == "boolean": diff --git a/back/db.sqlite3 b/back/db.sqlite3 index 50db6ebfb3d28517a933f8650b2430a921d3e424..9f8e18213a65a0090e546a253ad442f235486114 100644 GIT binary patch delta 243 zcmZqJ!Pc;YZGtr8$%!(~j3*ltwk9wxtX5@UVBlwnXJFpST*2(b%*J$!A)cv|$)8D> z@fzb2#$rYthKCHZCQh{Ew`erwV^C$3=HOsZOp)z|R;z!6zrNGQTXfsMw{^ zZn{nlqxJNHdd86Lnl+5EjO>1mW_%33jMMK$GHOkKSj(tjtl4P7#~=zah688}2cxK4 zVo@qnN@{XuZeos+fuW_YfswAEkxv>>*s{@>k3o}j`u!+I35Arzl2k)WOQ5`|u91;X lN@_u3QAuf0YCK57xY20(#9~HS7LbbR@pX)|mNhWS000_JLc0I} delta 266 zcmZqJ!Pc;YZGtr8hKVxHj2jvgwk9wxtkz&`W8i1dWMEpyRLEq_e1z#A6C>jWMju82 zhRX~K844IQnJbx%8f_T1>(nyFGO{rJWYC)4TgRxz<=1G&$KcB-&A~bSVI-sa^j&p~ z3jF4crhE*lKtT=$MP6Q}>3KDb3ViAUJ~@e%`DLj^#m0?B(XulP%9N6toSB=LeL)9*(yO30=pmZSnzo9P;u>KYmOq@)%k7L}A1rN)CK JmNhWS004J4N2LG&