I'm currently having a problem with DetailView based views and
querysets being cached.

If I use a custom manager function for the DetailView queryset, such
as SampleModel.objects.published() below, the first request caches the
queryset and any objects added after are inaccessible - the queryset
gets cached and any new entries result in a 404.

Changing queryset to SampleModel.objects.all() results in no queryset
caching, new objects are immediately visible without having to reload
the webserver.

Is there something I'm missing here?



### models.py:
from django.db import models
import datetime


class SampleModelManager(models.Manager):
    def published(self):
        return self.get_query_set().filter(published=True,
date__lte=datetime.datetime.now())


class SampleModel(models.Model):
    title = models.CharField(max_length=100, db_index=True)
    date = models.DateTimeField(default=datetime.datetime.now,
db_index=True)
    published = models.BooleanField(default=True, db_index=True)

    objects = SampleModelManager()

    def __unicode__(self):
        return self.title

    @models.permalink
    def get_absolute_url(self):
        return ('sample-model-detail', (), {
            'pk': str(self.pk),
        })


### urls.py:
from django.conf.urls.defaults import *
import views


urlpatterns = patterns('',
    url(r'^(?P<pk>\d+)/$',
        views.SampleModelDetailView.as_view(),
        name='sample-model-detail'),
)


###views.py:
from django.views.generic import DetailView
from models import SampleModel


class SampleModelDetailView(DetailView):
    queryset = SampleModel.objects.published()

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to