我有这个型号
class Person(models.Model):
name = models.CharField(max_length=150)
date_birth = models.DateField()
和这个属性来计算出生年月
@property
def eta_annimesi(self):
date2 = datetime.combine(self.date_birth , datetime.min.time())
now = datetime.now()
duration = (now.year - date2.year) * 12 + now.month - date2.month
years = duration // 12
months = duration % 12
if years > 0:
if months > 0:
msg_anni = years.__str__() + ' anni ' +months.__str__() +' mesi'
else:
msg_anni = years.__str__() + ' anni'
else:
if months > 0:
msg_anni = months.__str__() +' mesi'
else:
msg_anni = 'Appena nato'
return msg_anni
我需要在 html 页面上创建过滤器,以允许我在两个整数值之间创建一个范围。 (例如从 0 到 2 岁) 如果可能甚至几个月,但这并不重要。
我通过允许输入两个日期的范围来管理它,但这不是我需要的。
想法和建议? 在此先感谢任何想帮助我的人。