On Wed, May 12, 2010 at 1:06 PM, Nick <[email protected]> wrote:
> I am using a custom template tag called calculate age to produce an
> age in numbers based on a filter for a template tag.
>
> Here is the tag:
>
> def age(bday, d=None):
> if d is None:
> d = datetime.datetime.now()
> return (d.year - bday.year) - int((d.month, d.day) < (bday.month,
> bday.day))
>
> register.filter('age', age)
>
> here is how it is used in a template:
>
> {{ entry.DOB|age }} # that produces an age
>
>
> Here is the problem, not all of the entries in my DB have a date of
> birth (henceforth known as DOB).
>
> This raises and error.
>
[snip remainder]
Why not just handle it in the age filter itself:
def age(bday, d=None):
if not bday:
return 'N/A'
if d is None:
d = datetime.datetime.now()
... remainder of filter ...
?
Karen
--
http://tracey.org/kmt/
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
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.