Created
July 4, 2012 18:22
-
-
Save artofhuman/3048733 to your computer and use it in GitHub Desktop.
Django: Age declension template tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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