Example #1
0
def m_form(request):
	if request.method == 'POST':
		form = MetalsModelForm( QueryDict( request.POST['formdata']) )
		if form.is_valid():
			# Return New Summary, New Detail
			form.save()
			return JsonResponse({'result': 'Saved'})
		else:
			return JsonResponse({'result': 'Form has errors', 'errors': form.errors.as_json()})
	else:
		form = MetalsModelForm()
		return form
Example #2
0
def m_record_update(request):
	if request.method == 'POST':
		MetalId = int( request.POST['pkey'] )
		obj = get_object_or_404(models.MetalsTable, pk=MetalId)
		formdata = QueryDict( request.POST['formdata'] )
		print('PKEY: ', MetalId, 'OBJECT: ', obj, 'FORMDATA: ', formdata)
		form = MetalsModelForm(formdata, instance = obj )
		if form.is_valid():
			# Return New Summary, New Detail
			form.save()
			return JsonResponse({'result': 'Saved'})
		else:
			return JsonResponse({'result': 'Form has errors', 'errors': form.errors.as_json()})

	else: # method not POST
		return JsonResponse({'result': 'nopost'})