def new_record(request, patient_id): if request.method == 'POST': patient = get_object_or_404(Patient, id=patient_id) form = RecordForm(request.POST) if form.is_valid(): from django.template.response import TemplateResponse record = form.save(commit=False) record.patient = patient record.save() form.save_m2m() if record.to_social_work: record.create_social_work() return TemplateResponse( request, 'register/clinic_record/list.html', {'patient': patient} ) else: return JsonResponse({'status': 'ERROR', 'errors': form.errors})
def edit_record(request, record_id): from django.template.response import TemplateResponse record = get_object_or_404(Record, id=record_id) if request.method == 'GET': form = RecordForm(instance=record) return TemplateResponse( request, 'register/clinic_record/_form_edit.html', {'r_edit_form': form} ) else: form = RecordForm(request.POST, instance=record) if form.is_valid(): form.save() return TemplateResponse( request, 'register/clinic_record/list.html', {'patient': record.patient} ) else: return JsonResponse({'status': 'ERROR', 'errors': form.errors})