Format of timesince filter

后端 未结 3 1444
你的背包
你的背包 2021-02-02 01:04

Is there a way to use the {{date|timesince}} filter, but instead of having two adjacent units, only display one?

For example, my template is currently displ

3条回答
  •  别跟我提以往
    2021-02-02 01:40

    A quick and dirty way:

    Change the django source file $PYTHON_PATH/django/utils/timesince.py @line51(django1.7) :

    result = avoid_wrapping(name % count)
    return result  #add this line let timesince return here
    if i + 1 < len(TIMESINCE_CHUNKS):
        # Now get the second item
        seconds2, name2 = TIMESINCE_CHUNKS[i + 1]
        count2 = (since - (seconds * count)) // seconds2
        if count2 != 0:
            result += ugettext(', ') + avoid_wrapping(name2 % count2)
    return result  
    

提交回复
热议问题