I made a custom filter that tests for the date:

import datetime

from django import template
register = template.Library()

@register.filter('is_current')
def isPast(occurrence):
    if occurrence.date >= datetime.datetime.today().date():
        return True
    return False


which works, but is this the best way this can be handled? I'm still
relatively new to Django, and I can't help but think this can be
handled at the Database API level in some way that I'm overlooking.

Thoughts? Advice greatly appreciated.

On Jul 1, 11:51 am, Brandon Taylor <[EMAIL PROTECTED]> wrote:
> Hi everyone,
>
> I have Events and Occurrences of an Event. Occurrence contains a
> foreign_key for the Event.
> In my template, I need to display the Event and Occurrences as such:
>
> Event Title One
>     June 1, 2008 [times]
>     July 23, 2008 [times]
>
> Event Title Two
>     August 25, 2008 [times]
>     September 1, 2008 [times]
>
> But, I only want to display dates that are greater than, or equal to
> today. In my view, I am selecting Events as such:
>
> events_list =
> events.filter(occurrence__date__gte=datetime.datetime.today())
>
> Here's my template code:
> <ul>
>     {% for event in events_list %}
>         <li>{{ event.title }}
>               {% for occurrence in event.occurrence_set.all %}
>                   <ul>
>                       <li>
>                           {{ occurrence.date }}
>                       </li>
>                   </ul>
>               {% endfor %}
>         </li>
>     {% endfor %}
> </ul>
>
> Which is showing ALL of the occurrences, not just the ones with a date
> greater than today. Given the sample data set above, it shouldn't
> display the event for June. Can someone please help me out with this?
> I'd really appreciate some advice.
>
> TIA,
> Brandon
--~--~---------~--~----~------------~-------~--~----~
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