On Dec 23, 9:53 am, Alfonso <allanhender...@gmail.com> wrote:
> Hi,
>
> Trying to implement a very simple template tag that will output a
> company's age. So idea being if company was established in 1860 then
> it should output '148 years old' if my math is right ;-)
>
> this is what I've got:
>
> from django.template import *
>
> register = Library()
>
> @register.filter
> def age(comp_age):
> d = datetime.date.today()
> b = 1860
> comp_age = int(d.year - b)
> return comp_age
>
> No joy - any ideas, must be pretty simple !?
You didn't say what "No joy" means. Did you receive an error?
You say you want to implement a simple tag but what you've implemented
above is a filter. If you did mean to implement a tag, change change
@register.filter to @register.simple_tag.
-Rajesh D
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---