我正在开发用于跟踪光缆的Django应用程序.我遇到了我认为是相关管理员的问题,因为在某些模板中,我可以让它做我想做的事,但在其他模板中,我做不到.
我正在尝试做的一个工作示例:
<ul>
{% for lanroom in building.lanroom_set.all %}
<li><a href="/lanrooms/{{ lanroom.id }}/">{{ lanroom.lan_room_name }}</a></li>
{% endfor %}
</ul>
Run Code Online (Sandbox Code Playgroud)
这样做给了我一组LAN房间,这些房间的建筑物被详细查看为外键.
我想要做的是将一股电缆连接到适配器板连接器.所以该模板具有以下内容:
<li>Date Added: {{ adaptorplateconnector.date_added }}</li>
<li>Connector Type in {{ adaptorplateconnector }}:</li>
<ul>
<li><a href="/connectortypes/{{ adaptorplateconnector.connector_type_id.id }}/">{{ adaptorplateconnector.connector_type_id.type }}</a></li>
</ul>
<li>Strand connected to {{ adaptorplateconnector }}:
<ul>
{% for strand in adaptorplateconnector.strand_set.all %}
<ali><a href="/strands/{{ strand.id }}/">{{ strand }}</a></li>
{% endfor %}
</ul>
Run Code Online (Sandbox Code Playgroud)
然而,我没有得到任何连接到转接板连接器的绞线.以下是相关型号:
class AdaptorPlateConnector(models.Model):
adaptor_plate_id = models.ForeignKey('AdaptorPlate')
connector_type_id = models.ForeignKey('ConnectorType')
strand_position = models.CharField(max_length=200)
date_added = models.DateTimeField(auto_now_add=True)
def __unicode__(self): …Run Code Online (Sandbox Code Playgroud)