Simplify selecting get_queryset() vs get_query_set() -> use self.all()
parent
4bddac7c70
commit
4d526d8780
|
|
@ -38,23 +38,18 @@ class PolymorphicManager(models.Manager):
|
||||||
if django.VERSION < (1, 7):
|
if django.VERSION < (1, 7):
|
||||||
get_query_set = get_queryset
|
get_query_set = get_queryset
|
||||||
|
|
||||||
if django.VERSION >= (1,6):
|
|
||||||
# Should not be used for Django 1.4/1.5 all all, as that breaks the RelatedManager
|
|
||||||
def _get_queryset(self):
|
|
||||||
return self.get_queryset()
|
|
||||||
else:
|
|
||||||
# Django 1.5
|
|
||||||
def _get_queryset(self):
|
|
||||||
return self.get_query_set()
|
|
||||||
|
|
||||||
# Proxy all unknown method calls to the queryset, so that its members are
|
# Proxy all unknown method calls to the queryset, so that its members are
|
||||||
# directly accessible as PolymorphicModel.objects.*
|
# directly accessible as PolymorphicModel.objects.*
|
||||||
# The advantage of this method is that not yet known member functions of derived querysets will be proxied as well.
|
# The advantage of this method is that not yet known member functions of derived querysets will be proxied as well.
|
||||||
# We exclude any special functions (__) from this automatic proxying.
|
# We exclude any special functions (__) from this automatic proxying.
|
||||||
|
#
|
||||||
|
# NOTE: Fetching the queryset is done by calling self.all() here on purpose.
|
||||||
|
# By using .all(), the proper get_query_set()/get_queryset() will be used for each Django version.
|
||||||
|
# Django 1.4/1.5 need to use get_query_set(), because the RelatedManager overrides that.
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
if name.startswith('__'):
|
if name.startswith('__'):
|
||||||
return super(PolymorphicManager, self).__getattr__(self, name)
|
return super(PolymorphicManager, self).__getattr__(self, name)
|
||||||
return getattr(self._get_queryset(), name)
|
return getattr(self.all(), name)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return '%s (PolymorphicManager) using %s' % (self.__class__.__name__, self.queryset_class.__name__)
|
return '%s (PolymorphicManager) using %s' % (self.__class__.__name__, self.queryset_class.__name__)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue