0
过滤的DateField我使用Django的1.5.8Django的:在模板
我想在模板过滤Datefield
类型的数据,如下面的代码。
- 表达对
timesince
格式近期的文章 - 表达对
date
格式旧文章
some_template.html
{% for article in articles %}
{# recent articles #}
{% if article.created >= (now - 7 days) %}
{{ article.created|timesince }}
{# old articles more than one week past #}
{% else %}
{{ article.created|date:"m d" }}
{% endif %}
{% endfor %}
是否有处理由Django的{% if article.created >= (now - 7 days) %}
的解决方案自己的模板标签?
或者我是否必须制作新的自定义过滤器?