Django template tag to show null date as "still open" -


i have following code in django template:

{{date_from|date:"y-m"}} - {{date_to|default_if_none:"still open"|date:"y-m"}} 

i get:

  1. "2012-08 - "
  2. "2012-11 - 2012-08"
  3. .. rest of values correctly displayed.

i this:

  1. "2012-08 - still open"
  2. "2012-11 - 2012-08"
  3. .. rest of values correctly displayed.

do have suggestions? think not displayed because date object.

change order of filters. use default instead of default_if_none (date filter return empty string non-date/datetime object)

>>> t = template('{{date_to|date:"y-m"|default:"still open"}}') >>> t.render(context({'date_to': none})) u'still open' >>> t.render(context({'date_to': datetime.datetime.now()})) u'2014-04' 

Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -