我正在为一个模型写一个管理员。有一个名为的列modbus_address_mapping_valid
,它不是这个模型的成员。只有两个结果。它如何在页面中显示是/否图标
def modbus_address_mapping_valid(self,obj):
try:
mapping_valid = models.ModbusAddressMapping.objects.filter(object_id=obj.id)[0].valid
except Exception:
mapping_valid = False
if mapping_valid:
return u'<img src="/static/admin/img/icon-no.gif" alt="False">'
else:
return u'<img src="/static/admin/img/icon-no.gif" alt="False">'
modbus_address_mapping_valid.short_description = 'Modbus_mapping_validate_flag'