Skip to content

Instantly share code, notes, and snippets.

@artofhuman
Created July 4, 2012 18:22
Show Gist options
  • Save artofhuman/3048733 to your computer and use it in GitHub Desktop.
Save artofhuman/3048733 to your computer and use it in GitHub Desktop.
Django: Age declension template tag
@register.filter(name="age_declension")
def age_declension(age):
end = ''
num = None
if age >= 5 and age <= 14:
end = 'лет'
else:
num = (math.floor(age/10)*10)
if num == 1:
end = 'год'
elif num == 0:
end = 'лет'
elif num >= 2 and num <= 4:
end = 'года'
elif num >= 5 and num <= 9:
end = 'лет'
age = str(age)
return age + ' ' + end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment