Задать вопрос

Тел: +7 965 3737 888

485

Просмотров

0

Ответов

Date/time util template filters

<p><strong>Explanations:</strong></p>
<ul><li>the series "is_*_of" was created 'cos it's easier write: {% if 10|is_day_of:date and user %} than write: {% ifequal date.day 10 %}{% if user %}...</li>
<li>the series "inc/dec" is not complete, but can the extended to day, hour, minute, etc as you needs. It's util to inc 10 months since 05/31/2006 by example and get a 2007's date :)</li>
</ul><p><strong>Setup:</strong></p>
<p>Insert the snippet into an_app/templatetags/datetimeutils.py.</p>
<p><strong>Use in template:</strong></p>
<p>{% load datetimeutils %} and use filters as following:</p>
<ul><li>{{ 30|is_day_of:a_date_time_variable }}</li>
<li>{{ 11|is_month_of:a_date_time_variable }}</li>
<li>{{ 2006|is_year_of:a_date_time_variable }}</li>
<li>{{ 58|is_minute_of:a_date_time_variable }}</li>
<li>{{ 23|is_hour_of:a_date_time_variable }}</li>
<li>{{ a_date_time_variable|dec_year:2 }}</li>
<li>{{ a_date_time_variable|dec_month:2 }}</li>
<li>{{ a_date_time_variable|inc_year:2 }}</li>
<li>{{ a_date_time_variable|inc_month:2 }}</li>
</ul>

Вопрос полезен? Да0/Нет0
file_4931.py(1.2Кб)
None