On Tue, Nov 25, 2008 at 3:55 AM, sajal <[EMAIL PROTECTED]> wrote:

> Now Id like to show age of the people along with their names.
>
> I have a function which can calculate age callable via calculateAge
> (p.date_of_birth)  but how do I make pass this along with the person
> object?

There's several ways you could approach this:

1. Create a new template tag that takes in a person object and spits
out the age.  For example, {% get_age p %}

2. Add a current_age method to the Person model, that returns the
current age. For example {% p.current_age %}

3. Return a list of tuples in your context processor:

    return {'borntoday': [(calculateAge(p.date_of_birth), p) for p in
Person.objects.filter(date_of_birth__month=date.month,
date_of_birth__day=date.day)]}

   Then in your template:

   {% for age, person in borntoday %}
      Current age: {{age}} for person {{person}}
   {% endfor %}


Personally, if the current age of a person is something you'll be
using often, I'd add it to the model.

-- 
---
David Zhou
[EMAIL PROTECTED]

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to