On 11/14/06, Gabriel Puliatti <[EMAIL PROTECTED]> wrote: > > Hello, I have a model which is obsoleted after a certain date, so that > I can just retrieve the entries from database which are in the future, > and not those which have already passed. > > Since I can't get into the djangoproject database, I guess I should > try here. Is there a way to .get() or .filter() those which have a > date in the future, or get a boolean to be true after a certain date?
On one site I run, I like to separate the upcoming events (ie whose end_date is greater than or equal to the current date) from the past events. I have something like this in my urls.py: from datetime import datetime info_dict = { 'queryset': Event.objects.all(), } def get_upcoming(): return Event.objects.filter(end_date__gte=datetime.now()).order_by('end_date') urlpatterns = patterns('django.views.generic.list_detail', (r'^/?$', 'object_list', dict(info_dict,allow_empty=True, extra_context={'upcoming_events':get_upcoming})) ) The part of that which answers your question (I think) is: Event.objects.filter(end_date__gte=datetime.now()).order_by('end_date') Notice also that the 'upcoming_events' extra context is returned by a function. The reason for this is that I want datetime.now() to be called everytime the URL is accessed, not just the first time. Putting a function inside an 'extra_context' causes Django to call the function each time. Jay P. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---