Age - custom filter

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from django import template
import datetime

register = template.Library()

def age(bday, d=None):
    if d is None:
        d = datetime.date.today()
    return (d.year - bday.year) - int((d.month, d.day) < (bday.month, bday.day))

register.filter('age', age)

More like this

  1. Basic logic filters by mikeivanov 4 years, 8 months ago
  2. Simple Age Verification Middleware by eculver 2 years, 9 months ago
  3. SmartyPants Filter by obeattie 5 years, 1 month ago
  4. Credit calculator(ua-ru) by fordexa 3 years, 8 months ago
  5. table with n items per row using custom modulo tag by elgreengeeto 3 years, 5 months ago

Comments

Romain Hardouin (on January 13, 2010):

smart, thanks

#

(Forgotten your password?)