Zidek / django-basic-apps

Automatically exported from code.google.com/p/django-basic-apps
0 stars 0 forks source link

Published blog posts not returend by basic.blog.managers.PublicManager.published #16

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This is the code:

class PublicManager(Manager):
    """Returns published posts that are not in the future."""
    def __init__(self, *args, **kwargs):
        self.filter_dict = dict(status__gte=2, publish__lte=datetime.datetime.now())
        super(PublicManager, self).__init__(*args, **kwargs)

    def published(self):
        return self.get_query_set().filter(**self.filter_dict)

The publish date is created and cache in __init__ and never gets updated when 
published() is 
called. So only those posts that were published before the Django 
process/thread was started 
are returned by published().

Fix: don't store the filter dict in a variable, create it on the fly in 
published.

Original issue reported on code.google.com by eallik on 8 Oct 2008 at 8:46

GoogleCodeExporter commented 9 years ago
I propose changing the code to the following:

class PublicManager(Manager):
    """Returns published posts that are not in the future."""
    def published(self):
        return self.get_query_set().filter(status__gte=2, publish__lte=datetime.datetime.now())

Original comment by eallik on 8 Oct 2008 at 8:56

GoogleCodeExporter commented 9 years ago
Should be fixed now, thanks!

Original comment by npbor...@gmail.com on 15 Oct 2008 at 7:25