【发布时间】:2017-11-17 11:08:01
【问题描述】:
目前正在处理一个电子商务项目(使用 django-oscar),我在购物篮模板上显示产品时遇到了问题。
我使用{% regroup %} 标签是因为我有几种类型的产品:独立产品、父产品或子产品。每个篮子线对应一个产品,如果其中几个是共享同一个父产品的孩子,我希望他们重新组合到他们共同的父产品下。但是,我希望独立产品能够独立存在。
我的查询集如下:
in_stock_lines = request.basket \
.all_lines() \
.order_by('product__parent', 'date_created') \
.filter(attached_to=None, product__product_class__name='Produit standard', is_customized=False)
在basket.html:
{% regroup in_stock_lines by product.parent as parent_list %}
{% for parent in parent_list %}
{% if parent.grouper %}
{% include "basket/partials/_basket_non_customized_product.html" %}
{% else %}
{% include "basket/partials/_basket_non_customized_standalone_product.html" %}
{% endif %}
{% endfor %}
问题是我不希望重组在{% else %} 部分起作用,因为它们是独立产品,不应该重组。但是作为他们的product.parent,即石斑鱼是None,他们是。
有没有办法防止{% regroup %} 为某个石斑鱼价值行事?我可以在我的views.py 中进行两个不同的查询,以将独立产品与其他产品分开,并且不在{% regroup %} 中包含它们的模板,但如果可以的话,我想避免进行两个查询。
任何帮助表示赞赏!这是我在 Stackoverflow 上的第一个问题,如果我错过了一些关于我提问方式的基本规则,请见谅。
【问题讨论】:
标签: django django-templates django-oscar