Re: Dynamic age count

2008-12-24 Thread join.toget...@gmail.com

Look at the timesince filter in django's source for an example, as it
does almost exactly what you're looking for.

On Dec 23, 8:53 am, Alfonso  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 !?
>
> Thanks
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Dynamic age count

2008-12-23 Thread Rajesh Dhawan



On Dec 23, 9:53 am, Alfonso  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
-~--~~~~--~~--~--~---



Dynamic age count

2008-12-23 Thread Alfonso

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 !?

Thanks
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---