【发布时间】:2015-05-30 05:58:21
【问题描述】:
在模板中使用 {% for %} 时是否有过滤方法? 例如我得到了这个:
型号:
class Options(models.Model):
option = models.CharField(max_length=50)
class Brand(models.Model):
brand = models.CharField()
class Products(models.Model):
type = models.ForeignKey(Options)
brand = models.ManyToManyField(Brands)
在模板中:
{% for article in Options %}
{% for sth in products where type=article.0 %} <--- Is this possible ?
I need to make it iterable
//Do something
{% endfor %}
{% end for %}
有办法吗? 有什么不懂的就问吧:)
【问题讨论】:
-
您是在寻找ifequal 标签还是
==运算符? -
不,我正在寻找一个过滤器,比如 model.objects.filter(field="something"),但是可以在模板上使用,你明白吗?
标签: python django filter many-to-many