2014-04-28 22 views

回答

3

看看到timesince from django source code

chunks = (
    (60 * 60 * 24 * 365, ungettext_lazy('%d year', '%d years')), 
    (60 * 60 * 24 * 30, ungettext_lazy('%d month', '%d months')), 
    (60 * 60 * 24 * 7, ungettext_lazy('%d week', '%d weeks')), 
    (60 * 60 * 24, ungettext_lazy('%d day', '%d days')), 
    (60 * 60, ungettext_lazy('%d hour', '%d hours')), 
    (60, ungettext_lazy('%d minute', '%d minutes')) 
) 

的快速簡便的方法來改變它是wrote your custom template filter改變hoursHr

def my_time_abbr(value): 
    return value.replace('hours', 'Hr').replace('minutes','Min') 

在模板:

{{ somedata | timeuntil | my_time_abbr }} 

您也可以重寫timesince從頭開始過濾(從django timesince複製粘貼)如果您在國際化模式下工作。

+0

很好的回答,非常感謝! –