Py学习  »  问与答

django 模板多重循环问题

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

我在写一个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
 
4006 次点击  
文章 [ 2 ]  |  最新文章 11 年前