summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Plant <L.Plant.98@cantab.net>2014-11-24 15:31:41 +0000
committerLuke Plant <L.Plant.98@cantab.net>2014-11-24 15:36:46 +0000
commit3c317064d8dfef21ef83b4b496ea4cf0dc1eefa9 (patch)
tree415f1ebe2e02ca912850528ff127cbcc9dab53bf
parent276332d85c76a4de9fc1cb4bcb2f1636c0322414 (diff)
[1.6.x] Further fixes to the migration notes for get_query_set
This rename is very tricky for the case of subclasses which define get_query_set and haven't been updated yet, which applies to all projects in the form of RelatedManager from Django 1.5. Backport of 0c623da66406d1f20b5e26d497d57da5ad0de066 from master
-rw-r--r--docs/releases/1.6.txt31
1 files changed, 28 insertions, 3 deletions
diff --git a/docs/releases/1.6.txt b/docs/releases/1.6.txt
index 06d1a8d675..b473bcec65 100644
--- a/docs/releases/1.6.txt
+++ b/docs/releases/1.6.txt
@@ -1116,11 +1116,36 @@ you should rename the method and conditionally add an alias with the old name::
If you are writing a library that needs to call the ``get_queryset`` method and
must support old Django versions, you should write::
- get_queryset = (some_manager.get_queryset
- if hasattr(some_manager, 'get_queryset')
- else some_manager.get_query_set)
+ get_queryset = (some_manager.get_query_set
+ if hasattr(some_manager, 'get_query_set')
+ else some_manager.get_queryset)
return get_queryset() # etc
+In the general case of a custom manager that both implements its own
+``get_queryset`` method and calls that method, and needs to work with older Django
+versions, and libraries that have not been updated yet, it is useful to define
+a ``get_queryset_compat`` method as below and use it internally to your manager::
+
+ class YourCustomManager(models.Manager):
+ def get_queryset(self):
+ return YourCustomQuerySet() # for example
+
+ get_query_set = get_queryset
+
+ def active(self): # for example
+ return self.get_queryset_compat().filter(active=True)
+
+ def get_queryset_compat(self):
+ get_queryset = (self.get_query_set
+ if hasattr(self, 'get_query_set')
+ else self.get_queryset)
+ return get_queryset()
+
+This helps to minimize the changes that are needed, but also works correctly in
+the case of subclasses (such as ``RelatedManagers`` from Django 1.5) which might
+override either ``get_query_set`` or ``get_queryset``.
+
+
``shortcut`` view and URLconf
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~