Hi,

I think the simple

{% if entry.DOB %} {{ entry.DOB|age }}{% else  %} N/A {% endif %}

should work. Or, the other way around:

{% if not entry.DOB %} ...


You could also try testing in your filter:

def age(bday, d=None):
   if bday is None:
     return None
   ....

and use the default_if_none filter

{{ entry.DOB|age|default_if_none:"N/A" }}

This, however, doesn't seem to make sense:
>
> def detail(request, last_name, first_name):
>    r = get_object_or_404(Rep, Last_Name=last_name,
> First_Name=first_name)
>    if r.DOB == None:
>        r.DOB = NULLage
>    return render_to_response('Government/repsSingle.html', {'entry':
> r, 'NULLage': NULLage})
>
> The in the template:
>
> {% if NULLage %}

NULLage is never set by your test in the view, seems like it's a
constant value, and the if in the template would always evaluate the
same way (be it True or False).

HTH,
Nuno

On Wed, May 12, 2010 at 6:06 PM, Nick <nickt...@gmail.com> 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.
>
> I have tried to get around this many different ways. Here are few:
>
> {% ifequal entry.DOB None %} N/A {% else %}  {{ entry.DOB|age }} {%
> endif %}
>
> {% ifequal entry.DOB "None" %} N/A {% else %}  {{ entry.DOB|age }} {%
> endif %}
>
> {% if entry.DOB == None #I have custom operators set up and this logic
> works in the shell but not in the template %} N/A {% else %}
> {{ entry.DOB|age }} {% endif %}
>
> {% if entry.DOB == 'None' %} N/A {% else %}  {{ entry.DOB|age }} {%
> endif %}
>
> I've even tried it in my view:
>

>
> This is a good grief sort of error and is making my brain blood boil.
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.

Reply via email to