社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  问与答

django 模板多重循环问题

Macofee-weibo • 11 年前 • 4005 次点击  

我在写一个views时候,要在模板里多重循环。。

一个是订单表,一个是产品表,其中产品表和订单表中只有一个order_id进行关联。

现在我想循环 订单表的时候,同时循环出该订单所有产品。

我代码是这样写的

orderList = Orders.objects.filter(shop_id__in=List) 
for orderCountry in orderList:
    productList = Products.objects.filter(parent_id = orderCountry.order_id)
    orderCountry.country = Country.objects.get(country_code=orderCountry.country).country_zh_name
    orderCountry.shop_id = aliexpressToken.objects.get(resource_owner = orderCountry.shop_id).shop_name

这样的话,无法在模板页面循环出来

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/380
 
4005 次点击  
文章 [ 2 ]  |  最新文章 11 年前
Macofee-weibo
Reply   •   1 楼
Macofee-weibo    11 年前

已经做好了,谢谢

Py站长
Reply   •   2 楼
Py站长    11 年前

你可以先在View里处理好,做成简单数据模型后,然后再在模板里填写