def AddAppointment(request): if request.method == 'POST': form = AppointmentForm(request.POST, request.FILES) if form.is_valid(): form.save() return redirect('payment') else: form = AppointmentForm() return render(request, 'app.html', {'form': form})
def Appointment(request): if request.method == "POST": form = AppointmentForm(request.POST, request.FILES) if form.is_valid(): form.save() messages.success( request, ' your Appointment book successfully!!! please wait for confirmations' ) return redirect("Appointment") else: form = AppointmentForm(request.FILES) return render(request, "bookappoitment.html", {"form": form})
def post(self, request, *args, **kwargs): form = AppointmentForm(request.POST) if form.is_valid(): appointment_list = list( Appointment.objects.filter( datetime__gte=form.cleaned_data['datetime'] - datetime.timedelta(hours=1)).filter( datetime__lte=form.cleaned_data['datetime'] + datetime.timedelta(hours=1)).filter( doctor=form.cleaned_data['doctor'])) if appointment_list: messages.error(request, "Doctor is busy during this time.") return render(request, 'app/appointment/appointment.haml', {'form': form}) else: appointment = form.save(commit=False) patient = Patient.objects.get(user__id=request.user.id) appointment.patient = patient appointment.save() return HttpResponseRedirect( reverse('app:patient', args=(request.user.id, ))) else: return render(request, 'app/appointment/appointment.haml', {'form': form})