如何禁用 django-cms AppHooks 的缓存



我正在处理一个页面,其中有一个事件列表页面(未来事件(和一个事件回顾页面(过去的事件,存档(。

在这两个页面上,我都使用django-cms AppHook,因为我也有详细视图。

活动

结束后的第二天,该活动应隐藏在活动列表中,并在活动回顾页面上可见。但问题是事件仍在事件列表页面中。

models.py

# Managers
class EventsManager(models.Manager):
"""EventsManager."""
    def get_all(self):
        return super(EventsManager, self) 
            .filter(is_visible=True) 
            .order_by('-date')
    def get_all_future(self):
        return super(EventsManager, self) 
            .filter(is_visible=True) 
            .filter(date__gte=datetime.datetime.now()) 
            .order_by('date')
    def get_all_past(self):
        return super(EventsManager, self) 
            .filter(is_visible=True) 
            .filter(date__lt=datetime.datetime.now()) 
            .order_by('-date')

views.py

class EventListView(ListView):
    template_name = 'event_list.html'
    queryset = Events.objects.get_all_future()
    paginate_by = 10
    @never_cache
    def dispatch(self, *args, **kwargs):
        return super(EventListView, self).dispatch(*args, **kwargs)
class EventArchiveView(ListView):
    template_name = 'event_archive.html'
    queryset = Events.objects.get_all_past()
    paginate_by = 20
    @never_cache
    def dispatch(self, *args, **kwargs):
        return super(EventArchiveView, self).dispatch(*args, **kwargs)
    def get_context_data(self, **kwargs):
        context = super(EventArchiveView, self).get_context_data(**kwargs)
        context['is_arcive'] = True
        return context

我尝试使用@never_cache但事件仍在事件列表页面上。我认为这是一个缓存问题,但我不确定从哪里开始搜索。有什么建议吗?

我刚刚遇到了类似的问题,它与 Django CMS 无关。由于某种原因,我仅在生产中遇到了问题。解决方案是使用 class 方法 get_queryset(),而不是使用 queryset 变量定义我的查询集。由于某种原因,当使用 UWSGI 运行我的 django 应用程序时,sql 查询被缓存,我的日期过滤卡在我第一次查询的日期。

取代:

queryset = Events.objects.get_all_past()

跟:

def get_queryset(self): return Events.objects.get_all_past()

最新更新