Я хочу отобразить в PDF nome
из pavimento
на AvariaAdmin
, и я действительно не знаю, как это сделать.
http://prntscr.com/mmm5eo
МОИ модели
class Avaria(models.Model):
freguesia = models.ForeignKey(Freguesia, on_delete=models.CASCADE,verbose_name="Freguesia")
rua = models.ForeignKey(Rua, on_delete=models.CASCADE,verbose_name="Rua")
porta = models.PositiveIntegerField(verbose_name="Numero de polícia")
tipo_avaria = models.ForeignKey(Tipo_avaria, on_delete=models.CASCADE,verbose_name="Tipos de avaria")
class Pavimentacao(models.Model):
avaria = models.ForeignKey(Avaria, related_name='AvariaObjects',on_delete=models.CASCADE)
pavimento = models.ForeignKey(Pavimento, on_delete=models.CASCADE, verbose_name="Pavimento")
class Pavimento(models.Model):
nome = models.CharField("Pavimento",max_length=200)
МОЙ ДЕФ (ВНУТРИ AvariaAdmin)
def Imprimir(self, request, obj):
data = {
'obj':obj
}
pdf = render_to_pdf('daa/imprimir/avarias_pdf.html', data)
if pdf :
response = HttpResponse(pdf, content_type='application/pdf')
filename ="Avaria_%s.pdf" %("123451231")
content = "inline; filename='%s'" %(filename)
response['Content-Disposition'] = content
download = request.GET.get("download")
if download:
content = "attachment; filename='%s'" %(filename)
response['Content-Disposition'] = content
return response
return HttpResponse("Not found")
МОЙ HTML
<table style="width:100%">
<tr>
<th>ID:</th>
<th>Freguesia:</th>
<th>Rua:</th>
<th>Porta:</th>
<th>Tipo avaria:</th>
<th>Pavimento:</th>
</tr>
{% for item in obj %}
<tr>
<td>{{item.id}}</td>
<td>{{item.freguesia }}</td>
<td>{{item.rua}}</td>
<td>{{item.porta}} </td>
<td>{{item.tipo_avaria}} </td>
<td>{{item.pavimento}} </td>
</tr>
{% endfor %}
</table>