5

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?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
André Luiz
  • 6,642
  • 9
  • 55
  • 105

1 Answers1

10

You can import the functions in the model:

from django.contrib.humanize.templatetags.humanize import naturalday
natural_day = naturalday(value)
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
André Luiz
  • 6,642
  • 9
  • 55
  • 105