【发布时间】:2021-08-20 16:25:39
【问题描述】:
我想开发一个列表链接上的弹出窗口(请看截图)点击。弹出窗口也将是一个列表。 到目前为止,这是我下面的代码 模型类:
class PSCInscpection(models.Model):
vessel = models.ForeignKey(Vessel, on_delete=models.CASCADE, null=True)
inspection_id = models.CharField(max_length=100, null=False, unique=True)
followup_inspection = models.BooleanField(null=False, default=False)
date = models.DateTimeField(null=True, blank=True)
port = models.CharField(max_length=50, null=True, blank=True)
country = models.CharField(max_length=50, null=True, blank=True)
number_of_defects = models.PositiveIntegerField(null=True, blank=True)
days_detained = models.PositiveIntegerField(null=True, blank=True)
class PSCInscpectionDefects(models.Model):
pscinscpection = models.ForeignKey(PSCInscpection, on_delete=models.CASCADE, null=True)
inspection_id = models.CharField(max_length=100, null=False, blank=False)
defect_code = models.CharField(max_length=50, null=True, blank=True)
defect_text = models.CharField(max_length=255, null=True, blank=True)
class_is_responsible = models.CharField(max_length=50, null=True, blank=True)
defective_item_code = models.CharField(max_length=50, null=True, blank=True)
views.py
inspections = PSCInscpection.objects.filter(
vessel_id=self.kwargs['pk']).order_by('-date')
renderableInspections = []
for _insp in inspections:
item = {
"date": _insp.date.strftime("%Y-%m-%d"),
"port": _insp.port,
"country": _insp.country,
"defects": _insp.number_of_defects,
"detained": _insp.days_detained
}
renderableInspections.append(item)
context['inspections'] = renderableInspections
我从这个“PSCInscpection”对象和弹出窗口绑定的列表将从“PSCInscpectionDefects”对象绑定。请问有什么帮助吗?谢谢!
view.html:
{% for inspection in inspections %}
<tr>
<td>{{ inspection.date }}</td>
<td>{{ inspection.country }}</td>
<td>{{ inspection.port }}</td>
<td>
{% if inspection.defects %}
<a href="#">{{ inspection.defects }}</a>
{% else %}
{{ 0 }}
{% endif %}
</td>
<td>{{ inspection.detained|default:0 }} Days</td>
</tr>
{% endfor %}
【问题讨论】:
标签: python django modal-dialog popup