/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# -*- coding: utf-8 -*- from django import template register = template.Library() @register.filter def rupluralize(value, arg="дурак,дурака,дураков"): args = arg.split(",") if not value: return args[2] number = abs(int(value)) a = number % 10 b = number % 100 if (a == 1) and (b != 11): return args[0] elif (a > 1) and (a < 5) and ((b < 10) or (b > 20)): return args[1] else: return args[2]