0
我有Django應用程序,並設置正確的條件下問題的日期:如果時間越來越少後來有一天在Django應用程序
- 我要檢查,如果事件之前的超過24小時(1天) - 顯示天
- 我要檢查,如果它是事件發生前不到24小時(1天) - 顯示小時和分鐘
- 檢查事件是date_from之間DATE_TO
這裏是我的過濾器:
任務1
@register.filter(name='if_more_then_24')
def if_more_then_24(time):
return time + datetime.timedelta(hours=24) > timezone.now()
任務2
@register.filter(name='if_less_then_24')
def if_less_then_24(time):
return time + datetime.timedelta(hours=24) < timezone.now()
任務3
@register.filter(name='now_online')
def now_online(time):
return time < timezone.now()
@register.filter(name='not_online')
def not_online(time):
return time > timezone.now()
但是代碼沒有工作,因爲當我有 {{object.event_from}}十二月2016年11月11日下午5:00 ,今天是2016年12月12日,下午4:31。 計數器顯示時1:28而不是幾天
你必須比「不工作」更具體,你是否收到錯誤信息? – Will
@請檢查我的更新 –