首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打印django的医疗收据

打印django的医疗收据
EN

Stack Overflow用户
提问于 2020-05-17 21:35:50
回答 1查看 145关注 0票数 0

所以,我在一个医生的Django项目中工作,在这个项目中,我需要根据通过一个ModelForm插入到一个UpdateView中的值打印医疗收据,我面临着两个冲突。

  1. --我想让success_url将我重定向到同一个页面,比如按下表单中的“保存”或“提交”按钮,而不是将我发送到其他页面,只是停留在相同的页面上。
  2. --我想知道如何创建一个pdf以供打印,但基于该更新视图中插入的值,我在互联网上看到了一些教程,但它们只是将一些随机文本呈现到html模板中,并使用xhtml2pdf将其创建为PDF,并使用通用视图显示内容,但是我不知道该走哪条路,所以我可以用这些特定的值来创建一个pdf.

正如您在我的html中看到的,我有一个包含'Imprimir‘的锚标记的按钮,所以我的意思是进入update视图,填充所有必需的字段,保存内容,然后用保存的内容将我重定向到同一个页面,这样我就可以点击'Imprimir’按钮,用这个特定的内容创建一个PDF并打印它。

希望你能理解我在说什么。

HTML

代码语言:javascript
复制
{%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%}

模型

代码语言:javascript
复制
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)

视图

代码语言:javascript
复制
class AppointmentUpdateView(UpdateView):
    model = Consults
    form_class = ConsultForm
    template_name = 'appointments_update.html'
    success_url = '/appointments/appointmentlist'

Urls

代码语言:javascript
复制
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'),
]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-18 00:31:09

你应该在另一篇文章中问第二个问题。

对于#1,如果我正确地理解了您,您希望将用户重定向到同一个页面。如果是这样的话,您可以重写get_success_url以重定向到相同的路径。

代码语言:javascript
复制
class AppointmentUpdateView(UpdateView):
    def get_success_url(self):
        return reverse("appointmentupdate", kwargs=self.kwargs)

代码语言:javascript
复制
class AppointmentUpdateView(UpdateView):
    def get_success_url(self):
        return request.path
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61859133

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档