amr_aly

IF_in_Save_Patient

May 17th, 2021 (edited)
511
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if request.method == 'POST':
  2.         form = PatientsForm(request.POST or None, request.FILES or None)
  3.         if form.is_valid():
  4.             name = request.POST.get('name')
  5.             match = Patients.objects.filter(name=name).exists()
  6.             if not match:
  7.                save_form = form.save(commit=False)
  8.                save_form.save()
  9.                pat_id = save_form.id
  10.                messages.success(request, 'Saving process done ... ')
  11.                return redirect('patientdata:table_patient')
  12.            else:
  13.                messages.success(request, 'Barcode is already exists or Patient name is repeated')
  14.                return redirect(reverse('patientdata:save_patient'))
  15.     else:
  16.         form = PatientsForm()
RAW Paste Data