views:

32

answers:

1

Hi,
In my application I have the date of a talk and I want to compare this against the current date to see whether it should display View Attendance Record in my html page. What I am thinking is:

if (dateInDB <= currentDate)
    display View Attendance Record
else 
    don't display view attendance record

How would i convert this to code? Would I have to do this in the HTML or in an external file that the HTML accesses. If i was doing this in JSPs and Servlets I would make the comparison when it pulls out the date from the database and then set a boolean true but I don't know how to do this in django. Thanks in Advance,
Dean

+1  A: 

Django 1.2 supports boolean operators in if tags. If you are using 1.2 then you can pass a currentDate context variable of suitable type to the template and do a boolean comparison.

{% if dateInDB <= currentDate %}
    <display>
{% else %}
    <hide>
{% endif %}

Alternately you can write a custom filter to test if dateInDB <= currentDate.

@register.filter
def less_than_current_date(value):
    from datetime import datetime as DT
    return value <= DT.today()

{% if dateInDB|less_than_current_date %}
... etc ...
Manoj Govindan
I used the second way after just reading up on filters they are cool.
Dean