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) %}
的解決方案自己的模板標籤?
或者我是否必須製作新的自定義過濾器?