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?
humanize. A set of Django template filters useful for adding a “human touch” to data.
Contrib name is for software that has been contributed to the project, but which might not actually be maintained by the core developers. Naming it "contrib" or "Contrib" is a long-established convention, but there's really nothing special about the name, and it's usually only used by fairly large projects.
Django comes with a set of template filters to add a “human touch” to your data. It is used to translate numbers and dates into a human readable format.
You can import the functions in the model:
from django.contrib.humanize.templatetags.humanize import naturalday
natural_day = naturalday(value)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With