Reputation: 98
So, i'm working in a Django Project for a Doctor, in which i need to print the medical receipt based on the values inserted into a ModelForm through a UpdateView, there are two conflicts i am facing.
I would like that the success_url to redirect me to the same page, something like hitting the 'Save' or 'Submit' button from the form and not sending me to other page just stay in the same.
I would like to know how can i create a pdf to be printed but based on the values inserted in that updateview, i've seen some tutorials in the internet but they just render some random text into a html template and use xhtml2pdf to create it to PDF and showing the content using a generic View, but i don't know what path to take so i can use those specific values to create a pdf.
As you can see in my html i have a button with an anchor tag that holds 'Imprimir', so what i mean with all this is entering the update view, filling all the required fields, saving the content and redirecting me to the same page with the content saved, so that then i could hit the 'Imprimir' button, creating a PDF with this particular content and printing it.
Hope you could understand what i am talking about.
{%extends 'base.html'%}
{%load staticfiles%}
{%block body_block%}
<link rel="stylesheet" href="{%static 'appointments/css/appointment_update.css'%}">
<div class="Form">
<form method="POST">
<h3 id="Consult">Informacion de la consulta</h3>
<h3 id="Patient">Signos Vitales</h3>
<h3 id="Exams">Estudios:</h3>
<h3 id="System">Examinacion por Sistema</h3>
<h3 id="Physical">Examinacion Fisica</h3>
<h3 id="Diagnose">Diagnostico y Tratamiento</h3>
{%csrf_token%}
{{form.as_p}}
<input align="center" type="submit" value="Finalizar Consulta">
<button><a href="">Imprimir</a></button>
</form>
</div>
{%endblock%}
class Consults(models.Model):
#General Consult Info
Paciente = models.ForeignKey(Patient,on_delete=models.CASCADE,related_name='Paciente')
Fecha = models.DateField()
Motivo = models.CharField(max_length=500,null=True)
Padecimiento = models.CharField(max_length=500,null=True)
#Main Patient Info
Presion = models.CharField(max_length=20,blank=True,null=True)
Temperatura = models.FloatField(blank=True,null=True)
Peso = models.FloatField(blank=True,null=True)
Talla = models.FloatField(blank=True,null=True)
#Any Exams done before
Estudios = models.ImageField(upload_to='studies',blank=True)
#Interrogatory by System
Digestivo = models.CharField(max_length=500,blank=True,null=True)
Endocrino = models.CharField(max_length=500,blank=True,null=True)
Renal = models.CharField(max_length=500,blank=True,null=True)
Linfativo = models.CharField(max_length=500,blank=True,null=True)
Respiratorio = models.CharField(max_length=500,blank=True,null=True)
#Physical Exploration
Cabeza = models.CharField(max_length=500,blank=True,null=True)
Torax = models.CharField(max_length=500,blank=True,null=True)
#Diagnose
CIE_10 = models.ForeignKey(CIE_10,on_delete=models.DO_NOTHING,blank=True,null=True)
Detalle_de_Codigo = models.CharField(max_length=500,blank=True,null=True)
Diagnostico = models.CharField(max_length=500,blank=True,null=True)
Procedimiento = models.CharField(max_length=500,blank=True,null=True)
Analisis = models.CharField(max_length=500,blank=True,null=True)
#Treatment
Medicamento = models.CharField(max_length=500,blank=True,null=True)
Descripcion = models.CharField(max_length=500,blank=True,null=True)
Uso = models.CharField(max_length=500,blank=True,null=True)
Dosis = models.CharField(max_length=500,blank=True,null=True)
Acciones = models.CharField(max_length=500,blank=True,null=True)
class AppointmentUpdateView(UpdateView):
model = Consults
form_class = ConsultForm
template_name = 'appointments_update.html'
success_url = '/appointments/appointmentlist'
urlpatterns = [
path('',AppointmentIndexView.as_view(),name='appointmentindex'),
path('AddConsult',AddAppointmentView.as_view(),name='addappointment'),
path('appointmentslist/',AppointmentListView.as_view(),name='appointmentlist'),
path('<int:pk>',AddAppointmentDetailView.as_view(),name='appointmentdetail'),
path('update/<int:pk>',AppointmentUpdateView.as_view(),name='appointmentupdate'),
path('delete/<int:pk>',AppointmentDeleteView.as_view(),name='appointmentdelete'),
]
Upvotes: 0
Views: 219
Reputation: 13731
You should ask question #2 in another post.
For #1, if I understand you correctly, you'd like to redirect the user to the same page. If so, you can override get_success_url
to redirect to your same path.
class AppointmentUpdateView(UpdateView):
def get_success_url(self):
return reverse("appointmentupdate", kwargs=self.kwargs)
Or
class AppointmentUpdateView(UpdateView):
def get_success_url(self):
return request.path
Upvotes: 1