How to use django.contrib.humanize in a model
Asked Answered
D

1

6

I would like to use the django.contrib.humanize outside of a template, actually inside a model to humanize some dates in some text messages.

Is it possible? How can I do this?

Durfee answered 22/6, 2016 at 13:46 Comment(2)
Have you tried importing them directly? What happened?Aubert
Hi, thanks for commenting. I just found how to do it.Siegel
D
10

You can import the functions in the model:

from django.contrib.humanize.templatetags.humanize import naturalday
natural_day = naturalday(value)
Durfee answered 22/6, 2016 at 13:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.