Skip to content

Commit

Permalink
Merge pull request #80 from ebrelsford/master
Browse files Browse the repository at this point in the history
Use get_queryset() instead of get_query_set()
  • Loading branch information
robhudson committed Oct 21, 2014
2 parents 23e17c9 + f89f656 commit f827f05
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions caching/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import functools
import logging

import django
from django.conf import settings
from django.db import models
from django.db.models import signals
Expand Down Expand Up @@ -32,9 +33,12 @@ class CachingManager(models.Manager):
# Tell Django to use this manager when resolving foreign keys.
use_for_related_fields = True

def get_query_set(self):
def get_queryset(self):
return CachingQuerySet(self.model, using=self._db)

if django.VERSION < (1, 6):
get_query_set = get_queryset

def contribute_to_class(self, cls, name):
signals.post_save.connect(self.post_save, sender=cls)
signals.post_delete.connect(self.post_delete, sender=cls)
Expand All @@ -56,7 +60,7 @@ def raw(self, raw_query, params=None, *args, **kwargs):
using=self._db, *args, **kwargs)

def cache(self, timeout=DEFAULT_TIMEOUT):
return self.get_query_set().cache(timeout)
return self.get_queryset().cache(timeout)

def no_cache(self):
return self.cache(NO_CACHE)
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ that class and inherit from the :class:`~caching.base.CachingMixin`. If you
want related lookups (foreign keys) to hit the cache, ``CachingManager`` must
be the default manager. If you have multiple managers that should be cached,
return a :class:`~caching.base.CachingQuerySet` from the other manager's
``get_query_set`` method instead of subclassing ``CachingManager``, since that
``get_queryset`` method instead of subclassing ``CachingManager``, since that
would hook up the post_save and post_delete signals multiple times.

Here's what a minimal cached model looks like::
Expand Down

0 comments on commit f827f05

Please sign in to comment.