我创建了django模板动态表头,
我想从另一个模型中获取表头,并从数据模型中获取与表头相对应的数据。
我想要{{ data.field_name }} <== {{data.{{ header.{{header.field_id}} }}
但不起作用,
from asset_manager.models import (
AssetServiceCategory,
AssetField,
)
from asset.models import (
AssetList,
)
#---[ Start Views ]---#
#--[ Default Asset_manager View ]--#
class Asset_View(View):
#-[ Resuest GET URL:asset ]-#
def get(self, request, *args, **kwargs):
if not request.user.is_authenticated:
return redirect('/accounts/login/')
else:
template_name = [
'asset/asset.html',
'asset/asset/asset_service_category.html',
]
service_category = AssetServiceCategory.objects.all()
asset_list_header = AssetField.objects.filter(field_display="YES")
asset_list_data = AssetList.objects.all()
context = {
'service_category': service_category,
'asset_list_header' : asset_list_header,
'asset_list_data' : asset_list_data,
}
return render(request, template_name, context)
<table class="table table_asset_list">
<thead class="thead thead_asset_list">
<tr>
{% for header in asset_list_header %}
<th>{{ header.field_name }}</th>
{% endfor %}
</tr>
</thead>
<tbody class="tbody tbody_asset_list">
{% for header in asset_list_header %}
{% for data in asset_list_data %}
<tr>
<td>{{ data.{{header.field_id}} }}</td> <== This is not working...
</tr>
{% endfor %}
{% endfor %}
</tbody>
</table>