Proposal: add new template tag "age"

143 views
Skip to first unread message

Paulo Maciel

unread,
Nov 9, 2015, 2:43:46 PM11/9/15
to Django developers (Contributions to Django itself)
My proposal is to add a new template tag "age": {{ birthday|age }}.
I think it is a common need for many users know the age from a date.


Tim Graham

unread,
Nov 9, 2015, 2:52:05 PM11/9/15
to Django developers (Contributions to Django itself)
For questions of whether or not to include something like this in core, my own rule of thumb is, "Is this difficult to implement as a third-party package? If not, do more than ~80% of sites need this feature?" If the answer to both questions is "no" (which is the case here, in my opinion), then I don't favor including it in Django.

For historic reasons we have some filters like phone2numeric which likely don't meet this criteria. I don't see much benefit to deprecating them, but let's not add more. Other opinions welcome.

Dheerendra Rathor

unread,
Nov 9, 2015, 9:57:41 PM11/9/15
to Django developers (Contributions to Django itself)
If we ever need to implement age filter, I would rather suggest for modification of naturaltime in django.contrib.humanize to take an optional parameter (age = True). 

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/d9ce1b89-1af0-4038-816f-24e13d25a666%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marc Tamlyn

unread,
Nov 10, 2015, 1:50:48 PM11/10/15
to django-d...@googlegroups.com

Agreed, this does not belong on core. In particular the formatting of a duration varies widely depending on the expected age range, languages and site context. Naturaltime is one implementation, the specific case you seem to be hinting at is a count of years, which is definitely too particular for Django inclusion. would make a perfect third party app though!

Mar

Jamie Norrish

unread,
Nov 10, 2015, 2:57:57 PM11/10/15
to django-d...@googlegroups.com
On Tue, 2015-11-10 at 18:50 +0000, Marc Tamlyn wrote:

> Agreed, this does not belong on core. In particular the formatting of
> a duration varies widely depending on the expected age range,
> languages and site context. Naturaltime is one implementation, the
> specific case you seem to be hinting at is a count of years, which is
> definitely too particular for Django inclusion. would make a perfect
> third party app though!

Further, age (for people, at least) is measured in different ways
around the world. See for example https://en.wikipedia.org/wiki/East_As
ian_age_reckoning

Jamie

Collin Anderson

unread,
Nov 11, 2015, 5:44:14 PM11/11/15
to Django developers (Contributions to Django itself), ja...@artefact.org.nz
Also, doing this from the backend seems like sub-par way to do it. I would recommend implementing this in javascript, so it can auto-update over time if you leave the window open.

Tim Chase

unread,
Nov 11, 2015, 6:01:19 PM11/11/15
to django-d...@googlegroups.com
On 2015-11-11 14:44, Collin Anderson wrote:
> Also, doing this from the backend seems like sub-par way to do it.
> I would recommend implementing this in javascript, so it can
> auto-update over time if you leave the window open.

It shouldn't be limited to one or the other: doing it on the
back-end will allow it to correctly reflect the age as of the time
the request was made (and thus be available where JS is
unavailable/disabled). That field can then be updated client-side
with JS if it's available.

-tkc



Reply all
Reply to author
Forward
0 new messages