我有一个列表显示在模板中:
编辑:这是模板中更完整的代码:
{% for assertions in badge_assertions_by_type %}
{{assertions.badge_type.name}}
{% for assertion in assertions.list %}
{{assertion.badge.name}}
{{assertion.time_issued}}
{% endfor %}
{% endfor %}
badge_assertions_by_type是defined here。
{{assertions.list}}
看起来像这样:
[<BadgeAssertion: MyBadge#1>, <BadgeAssertion: MyBadge#1>, <BadgeAssertion: MyBadge#1>, <BadgeAssertion: MyBadge#1>, <BadgeAssertion: MyBadge#2>]
我不想显示所有这些项目,而只想显示唯一的项目,数字显示多少,例如而不是:
MyBadge#1
MyBadge#1
MyBadge#1
MyBadge#1
MyBadge#2
我想要这样的事情,最好在模板中完成:
MyBadge#1 (x4)
MyBadge#2
显示的文本实际上是{{assertion.badge.name}},它与BadgeAssertion模型的__str__
相同,这就是它在{{assertions.list}}中看起来相同的原因
assertions.list来自更高层的其他东西(参见here,在那里它被混淆地称为badges.list)
模特:
class Badge(models.Model):
name = models.CharField(max_length=50, unique=True)
...
class BadgeAssertion(models.Model):
badge = models.ForeignKey(Badge)
...
答案 0 :(得分:0)
使用不同的计数,如下:
export LIBPATH=/usr/lib
export CONFIG_SHELL=/usr/bin/ksh93
export OBJECT_MODE=64
./configure --enable-shared --enable-load-relative --disable-install-doc --prefix=your_install_path_here --exec-prefix=your_install_path_here/aix CC="gcc" CFLAGS="-maix64 -mminimal-toc" CXX="g++" CXXFLAGS="-maix64 -mminimal-toc" NM="nm -X64" AR="ar -X64" LDFLAGS="-maix64 -Wl,-bbigtoc" EXTLDFLAGS="-maix64 -Wl,-bbigtoc" DLDFLAGS="-shared -maix64 -Wl,-bbigtoc"