私信  •  关注

Dharman CPSuperstore

Dharman CPSuperstore 最近创建的主题
Dharman CPSuperstore 最近回复了
3 年前
回复了 Dharman CPSuperstore 创建的主题 » 如何迭代两个django模型

请像这样的用户转换queryset模型到列表,然后添加到列表中。。。所有列表的类型是元组列表。 然后 您必须将列表转换为zip。。 将此zip文件传递到数据帧。这将自动管理zip文件,以正确的列格式提供数据。。

inventory = list(Inventory.objects.all())
header = list(Header.objects.all())
setup = list(Setup.objects.all())
revision = list(Revisions.objects.all())
spec = list(SpecificationDetails.objects.all())
review = list(Reviewers.objects.all())
iterates = inventory + header + setup + revision + spec + review

zip_file = list(zip(iterates))

import pandas as pd

df = pd.DataFrame(zip_file, columns = ['Inventory', 'Header','Setup','Revisoin','Spec','Review'])

context = {
        'df':  df
}
return render(request, 'crud/dashboard.html', df)