所以,我在一个医生的Django项目中工作,在这个项目中,我需要根据通过一个ModelForm插入到一个UpdateView中的值打印医疗收据,我面临着两个冲突。
正如您在我的html中看到的,我有一个包含'Imprimir‘的锚标记的按钮,所以我的意思是进入update视图,填充所有必需的字段,保存内容,然后用保存的内容将我重定向到同一个页面,这样我就可以点击'Imprimir’按钮,用这个特定的内容创建一个PDF并打印它。
希望你能理解我在说什么。
HTML
{%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'Urls
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'),
]发布于 2020-05-18 00:31:09
你应该在另一篇文章中问第二个问题。
对于#1,如果我正确地理解了您,您希望将用户重定向到同一个页面。如果是这样的话,您可以重写get_success_url以重定向到相同的路径。
class AppointmentUpdateView(UpdateView):
def get_success_url(self):
return reverse("appointmentupdate", kwargs=self.kwargs)或
class AppointmentUpdateView(UpdateView):
def get_success_url(self):
return request.pathhttps://stackoverflow.com/questions/61859133
复制相似问题