def editId(request, pid): if request.method == 'POST': payload = json.loads(request.body) this_place = Place.objects.get(id = pid) this_place.name = payload.get('name', None) this_token = PlaceToken(place = this_place, key = payload.get('key', None), value = payload.get('value', None)) this_place.save() this_token.save() return HttpResponse('Success') else: return HttpResponseBadRequest('Missing POST data')
def addToken(request, pid): if request.method == 'POST': payload = json.loads(request.body) try: this_place = Place.objects.get(id = pid) this_token = PlaceToken(place = this_place, key = payload.get('key', None), value = payload.get('value', None)) this_token.save() return HttpResponse('Success') except Exception as e: return HttpResponseBadRequest(str(e)) else: return HttpResponseBadRequest('Missing POST data')