def update_thing(request, id): if request.method == 'POST': a = thing() form = thing_forms(request.POST) if form.is_valid(): a.info = form.cleaned_data['info'] try: b = thing.objects.get(id=id) except: return HttpResponse(json.dumps({ 'result': 'error', 'message': 'the thing DNE' }), content_type='application/json') else: b.info = a.info b.save() return HttpResponse(json.dumps({ 'result': 'ok', 'message': 'update successful' }), content_type='application/json') else: form = thing_forms() return render(request, 'update_thing.html', {"form": form})
def create_thing(request): if request.method == 'POST': a = thing() form = thing_forms(request.POST) if form.is_valid(): a.info = form.cleaned_data['info'] a.save() return HttpResponse(json.dumps({'result': 'ok', 'info': a.info}), content_type='application/json') else: form = thing_forms() return render(request, 'create_thing.html', {"form":form})