Building on Marcelo's response, and an example from James Bennett's book (Ch
5), you could also add a custom manager. It'd go something like this:
class PublishedEntryManager(models.Manager):
def get_query_set(self):
return super(PublishedEntryManager,
self).get_query_set().filter(pub_date__lte=datetime.now())
class Entry(models.Model)
title = ...etc...
content = ...etc...
objects = models.Manager()
published = PublishedEntryManager
Entry.published.all() will return a queryset of all published Entries.
keith
On Fri, Sep 12, 2008 at 3:12 AM, Marcelo Ramos <[EMAIL PROTECTED]> wrote:
>
> 2008/9/12 Dana <[EMAIL PROTECTED]>:
> >
> > Hey all,
> >
> > Wondering what the best technique would be to make sure that an entry
> > (such as a blog entry/story/etc...) with a datetime object 'pub_date'
> > does not show up on the front end if the pub_date is in the future. I
> > would assume using ".filter(...something...)" is the way to go but
> > what would be the best filter to apply? Any other ways to achieve
> > this?
>
> Yes, a filter is a good option. For example:
>
> from datetime import datetime
>
> .objects.filter(pub_date__lte=datetime.now())
>
> Regards.
>
> --
> Marcelo Ramos
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---