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:
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 %}
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 [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.