-
From 22ea27f04e5684ca81c633bc5d2615cfb52ba46a Mon Sep 17 00:00:00 2001
From: Simon Charette <charette.s@gmail.com>
Date: Sun, 3 Feb 2013 05:10:35 -0500
Subject: [PATCH] Fixed #15363 -- Renamed get_query_set methods by
get_queryset
---
django/contrib/admin/options.py | 6 +-
django/contrib/admin/views/main.py | 6 +-
django/contrib/comments/managers.py | 4 +-
django/contrib/comments/templatetags/comments.py | 9 ++-
django/contrib/contenttypes/generic.py | 8 ++-
django/contrib/gis/db/models/manager.py | 65 +++++++++---------
django/contrib/sites/managers.py | 7 +-
django/db/models/fields/related.py | 34 ++++++----
django/db/models/manager.py | 69 ++++++++++----------
django/forms/models.py | 6 +-
django/utils/deprecation.py | 16 +++++
tests/modeltests/custom_managers/models.py | 10 +--
tests/modeltests/fixtures/models.py | 4 +-
tests/modeltests/generic_relations/models.py | 4 +-
tests/modeltests/get_object_or_404/models.py | 4 +-
tests/modeltests/prefetch_related/models.py | 4 +-
tests/modeltests/proxy_models/models.py | 8 +--
tests/regressiontests/admin_changelist/models.py | 4 +-
tests/regressiontests/admin_changelist/tests.py | 2 +-
tests/regressiontests/admin_filters/tests.py | 46 ++++++-------
tests/regressiontests/admin_views/admin.py | 2 +-
tests/regressiontests/admin_widgets/models.py | 4 +-
.../custom_managers_regress/models.py | 4 +-
tests/regressiontests/managers_regress/models.py | 12 ++--
tests/regressiontests/modeladmin/tests.py | 2 +-
tests/regressiontests/queries/models.py | 8 +--
.../reverse_single_related/models.py | 4 +-
27 files changed, 195 insertions(+), 157 deletions(-)
create mode 100644 django/utils/deprecation.py
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 8e0aacc..8d42313 100644
a
|
b
|
class BaseModelAdmin(six.with_metaclass(forms.MediaDefiningClass)):
|
222 | 222 | Returns a QuerySet of all model instances that can be edited by the |
223 | 223 | admin site. This is used by changelist_view. |
224 | 224 | """ |
225 | | qs = self.model._default_manager.get_query_set() |
| 225 | qs = self.model._default_manager.get_queryset() |
226 | 226 | # TODO: this should be handled by some parameter to the ChangeList. |
227 | 227 | ordering = self.get_ordering(request) |
228 | 228 | if ordering: |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1187 | 1187 | if (actions and request.method == 'POST' and |
1188 | 1188 | 'index' in request.POST and '_save' not in request.POST): |
1189 | 1189 | if selected: |
1190 | | response = self.response_action(request, queryset=cl.get_query_set(request)) |
| 1190 | response = self.response_action(request, queryset=cl.get_queryset(request)) |
1191 | 1191 | if response: |
1192 | 1192 | return response |
1193 | 1193 | else: |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1203 | 1203 | helpers.ACTION_CHECKBOX_NAME in request.POST and |
1204 | 1204 | 'index' not in request.POST and '_save' not in request.POST): |
1205 | 1205 | if selected: |
1206 | | response = self.response_action(request, queryset=cl.get_query_set(request)) |
| 1206 | response = self.response_action(request, queryset=cl.get_queryset(request)) |
1207 | 1207 | if response: |
1208 | 1208 | return response |
1209 | 1209 | else: |
-
diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py
index be7067f..02b45f1 100644
a
|
b
|
from django.core.urlresolvers import reverse
|
7 | 7 | from django.db import models |
8 | 8 | from django.db.models.fields import FieldDoesNotExist |
9 | 9 | from django.utils.datastructures import SortedDict |
| 10 | from django.utils.deprecation import deprecated_get_query_set |
10 | 11 | from django.utils.encoding import force_str, force_text |
11 | 12 | from django.utils.translation import ugettext, ugettext_lazy |
12 | 13 | from django.utils.http import urlencode |
… |
… |
IGNORED_PARAMS = (
|
33 | 34 | EMPTY_CHANGELIST_VALUE = ugettext_lazy('(None)') |
34 | 35 | |
35 | 36 | |
| 37 | @deprecated_get_query_set |
36 | 38 | class ChangeList(object): |
37 | 39 | def __init__(self, request, model, list_display, list_display_links, |
38 | 40 | list_filter, date_hierarchy, search_fields, list_select_related, |
… |
… |
class ChangeList(object):
|
70 | 72 | else: |
71 | 73 | self.list_editable = list_editable |
72 | 74 | self.query = request.GET.get(SEARCH_VAR, '') |
73 | | self.query_set = self.get_query_set(request) |
| 75 | self.query_set = self.get_queryset(request) |
74 | 76 | self.get_results(request) |
75 | 77 | if self.is_popup: |
76 | 78 | title = ugettext('Select %s') |
… |
… |
class ChangeList(object):
|
297 | 299 | ordering_fields[idx] = 'desc' if pfx == '-' else 'asc' |
298 | 300 | return ordering_fields |
299 | 301 | |
300 | | def get_query_set(self, request): |
| 302 | def get_queryset(self, request): |
301 | 303 | # First, we collect all the declared list filters. |
302 | 304 | (self.filter_specs, self.has_filters, remaining_lookup_params, |
303 | 305 | use_distinct) = self.get_filters(request) |
-
diff --git a/django/contrib/comments/managers.py b/django/contrib/comments/managers.py
index bc0fc5f..6562004 100644
a
|
b
|
class CommentManager(models.Manager):
|
8 | 8 | """ |
9 | 9 | QuerySet for all comments currently in the moderation queue. |
10 | 10 | """ |
11 | | return self.get_query_set().filter(is_public=False, is_removed=False) |
| 11 | return self.get_queryset().filter(is_public=False, is_removed=False) |
12 | 12 | |
13 | 13 | def for_model(self, model): |
14 | 14 | """ |
… |
… |
class CommentManager(models.Manager):
|
16 | 16 | a class). |
17 | 17 | """ |
18 | 18 | ct = ContentType.objects.get_for_model(model) |
19 | | qs = self.get_query_set().filter(content_type=ct) |
| 19 | qs = self.get_queryset().filter(content_type=ct) |
20 | 20 | if isinstance(model, models.Model): |
21 | 21 | qs = qs.filter(object_pk=force_text(model._get_pk_val())) |
22 | 22 | return qs |
-
diff --git a/django/contrib/comments/templatetags/comments.py b/django/contrib/comments/templatetags/comments.py
index 4d4eb23..e82fbed 100644
a
|
b
|
from django.template.loader import render_to_string
|
3 | 3 | from django.conf import settings |
4 | 4 | from django.contrib.contenttypes.models import ContentType |
5 | 5 | from django.contrib import comments |
| 6 | from django.utils.deprecation import deprecated_get_query_set |
6 | 7 | from django.utils.encoding import smart_text |
7 | 8 | |
8 | 9 | register = template.Library() |
9 | 10 | |
| 11 | |
| 12 | @deprecated_get_query_set |
10 | 13 | class BaseCommentNode(template.Node): |
11 | 14 | """ |
12 | 15 | Base helper class (abstract) for handling the get_comment_* template tags. |
… |
… |
class BaseCommentNode(template.Node):
|
64 | 67 | self.comment = comment |
65 | 68 | |
66 | 69 | def render(self, context): |
67 | | qs = self.get_query_set(context) |
| 70 | qs = self.get_queryset(context) |
68 | 71 | context[self.as_varname] = self.get_context_value_from_queryset(context, qs) |
69 | 72 | return '' |
70 | 73 | |
71 | | def get_query_set(self, context): |
| 74 | def get_queryset(self, context): |
72 | 75 | ctype, object_pk = self.get_target_ctype_pk(context) |
73 | 76 | if not object_pk: |
74 | 77 | return self.comment_model.objects.none() |
… |
… |
class RenderCommentListNode(CommentListNode):
|
205 | 208 | "comments/%s/list.html" % ctype.app_label, |
206 | 209 | "comments/list.html" |
207 | 210 | ] |
208 | | qs = self.get_query_set(context) |
| 211 | qs = self.get_queryset(context) |
209 | 212 | context.push() |
210 | 213 | liststr = render_to_string(template_search_list, { |
211 | 214 | "comment_list" : self.get_context_value_from_queryset(context, qs) |
-
diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py
index cda4d46..ca9f018 100644
a
|
b
|
from django.forms import ModelForm
|
16 | 16 | from django.forms.models import BaseModelFormSet, modelformset_factory, save_instance |
17 | 17 | from django.contrib.admin.options import InlineModelAdmin, flatten_fieldsets |
18 | 18 | from django.contrib.contenttypes.models import ContentType |
| 19 | from django.utils.deprecation import deprecated_get_query_set |
19 | 20 | from django.utils.encoding import smart_text |
20 | 21 | |
21 | 22 | |
… |
… |
def create_generic_related_manager(superclass):
|
294 | 295 | Manager) and adds behavior for generic related objects. |
295 | 296 | """ |
296 | 297 | |
| 298 | @deprecated_get_query_set |
297 | 299 | class GenericRelatedObjectManager(superclass): |
298 | 300 | def __init__(self, model=None, instance=None, symmetrical=None, |
299 | 301 | source_col_name=None, target_col_name=None, content_type=None, |
… |
… |
def create_generic_related_manager(superclass):
|
316 | 318 | '%s__exact' % object_id_field_name: instance._get_pk_val(), |
317 | 319 | } |
318 | 320 | |
319 | | def get_query_set(self): |
| 321 | def get_queryset(self): |
320 | 322 | try: |
321 | 323 | return self.instance._prefetched_objects_cache[self.prefetch_cache_name] |
322 | 324 | except (AttributeError, KeyError): |
323 | 325 | db = self._db or router.db_for_read(self.model, instance=self.instance) |
324 | | return super(GenericRelatedObjectManager, self).get_query_set().using(db).filter(**self.core_filters) |
| 326 | return super(GenericRelatedObjectManager, self).get_queryset().using(db).filter(**self.core_filters) |
325 | 327 | |
326 | 328 | def get_prefetch_query_set(self, instances): |
327 | 329 | db = self._db or router.db_for_read(self.model, instance=instances[0]) |
… |
… |
def create_generic_related_manager(superclass):
|
330 | 332 | '%s__in' % self.object_id_field_name: |
331 | 333 | set(obj._get_pk_val() for obj in instances) |
332 | 334 | } |
333 | | qs = super(GenericRelatedObjectManager, self).get_query_set().using(db).filter(**query) |
| 335 | qs = super(GenericRelatedObjectManager, self).get_queryset().using(db).filter(**query) |
334 | 336 | # We (possibly) need to convert object IDs to the type of the |
335 | 337 | # instances' PK in order to match up instances: |
336 | 338 | object_id_converter = instances[0]._meta.pk.to_python |
-
diff --git a/django/contrib/gis/db/models/manager.py b/django/contrib/gis/db/models/manager.py
index 61fb821..9cd101e 100644
a
|
b
|
|
1 | 1 | from django.db.models.manager import Manager |
2 | 2 | from django.contrib.gis.db.models.query import GeoQuerySet |
| 3 | from django.utils.deprecation import deprecated_get_query_set |
3 | 4 | |
| 5 | |
| 6 | @deprecated_get_query_set |
4 | 7 | class GeoManager(Manager): |
5 | 8 | "Overrides Manager to return Geographic QuerySets." |
6 | 9 | |
… |
… |
class GeoManager(Manager):
|
9 | 12 | # properly. |
10 | 13 | use_for_related_fields = True |
11 | 14 | |
12 | | def get_query_set(self): |
| 15 | def get_queryset(self): |
13 | 16 | return GeoQuerySet(self.model, using=self._db) |
14 | 17 | |
15 | 18 | def area(self, *args, **kwargs): |
16 | | return self.get_query_set().area(*args, **kwargs) |
| 19 | return self.get_queryset().area(*args, **kwargs) |
17 | 20 | |
18 | 21 | def centroid(self, *args, **kwargs): |
19 | | return self.get_query_set().centroid(*args, **kwargs) |
| 22 | return self.get_queryset().centroid(*args, **kwargs) |
20 | 23 | |
21 | 24 | def collect(self, *args, **kwargs): |
22 | | return self.get_query_set().collect(*args, **kwargs) |
| 25 | return self.get_queryset().collect(*args, **kwargs) |
23 | 26 | |
24 | 27 | def difference(self, *args, **kwargs): |
25 | | return self.get_query_set().difference(*args, **kwargs) |
| 28 | return self.get_queryset().difference(*args, **kwargs) |
26 | 29 | |
27 | 30 | def distance(self, *args, **kwargs): |
28 | | return self.get_query_set().distance(*args, **kwargs) |
| 31 | return self.get_queryset().distance(*args, **kwargs) |
29 | 32 | |
30 | 33 | def envelope(self, *args, **kwargs): |
31 | | return self.get_query_set().envelope(*args, **kwargs) |
| 34 | return self.get_queryset().envelope(*args, **kwargs) |
32 | 35 | |
33 | 36 | def extent(self, *args, **kwargs): |
34 | | return self.get_query_set().extent(*args, **kwargs) |
| 37 | return self.get_queryset().extent(*args, **kwargs) |
35 | 38 | |
36 | 39 | def extent3d(self, *args, **kwargs): |
37 | | return self.get_query_set().extent3d(*args, **kwargs) |
| 40 | return self.get_queryset().extent3d(*args, **kwargs) |
38 | 41 | |
39 | 42 | def force_rhr(self, *args, **kwargs): |
40 | | return self.get_query_set().force_rhr(*args, **kwargs) |
| 43 | return self.get_queryset().force_rhr(*args, **kwargs) |
41 | 44 | |
42 | 45 | def geohash(self, *args, **kwargs): |
43 | | return self.get_query_set().geohash(*args, **kwargs) |
| 46 | return self.get_queryset().geohash(*args, **kwargs) |
44 | 47 | |
45 | 48 | def geojson(self, *args, **kwargs): |
46 | | return self.get_query_set().geojson(*args, **kwargs) |
| 49 | return self.get_queryset().geojson(*args, **kwargs) |
47 | 50 | |
48 | 51 | def gml(self, *args, **kwargs): |
49 | | return self.get_query_set().gml(*args, **kwargs) |
| 52 | return self.get_queryset().gml(*args, **kwargs) |
50 | 53 | |
51 | 54 | def intersection(self, *args, **kwargs): |
52 | | return self.get_query_set().intersection(*args, **kwargs) |
| 55 | return self.get_queryset().intersection(*args, **kwargs) |
53 | 56 | |
54 | 57 | def kml(self, *args, **kwargs): |
55 | | return self.get_query_set().kml(*args, **kwargs) |
| 58 | return self.get_queryset().kml(*args, **kwargs) |
56 | 59 | |
57 | 60 | def length(self, *args, **kwargs): |
58 | | return self.get_query_set().length(*args, **kwargs) |
| 61 | return self.get_queryset().length(*args, **kwargs) |
59 | 62 | |
60 | 63 | def make_line(self, *args, **kwargs): |
61 | | return self.get_query_set().make_line(*args, **kwargs) |
| 64 | return self.get_queryset().make_line(*args, **kwargs) |
62 | 65 | |
63 | 66 | def mem_size(self, *args, **kwargs): |
64 | | return self.get_query_set().mem_size(*args, **kwargs) |
| 67 | return self.get_queryset().mem_size(*args, **kwargs) |
65 | 68 | |
66 | 69 | def num_geom(self, *args, **kwargs): |
67 | | return self.get_query_set().num_geom(*args, **kwargs) |
| 70 | return self.get_queryset().num_geom(*args, **kwargs) |
68 | 71 | |
69 | 72 | def num_points(self, *args, **kwargs): |
70 | | return self.get_query_set().num_points(*args, **kwargs) |
| 73 | return self.get_queryset().num_points(*args, **kwargs) |
71 | 74 | |
72 | 75 | def perimeter(self, *args, **kwargs): |
73 | | return self.get_query_set().perimeter(*args, **kwargs) |
| 76 | return self.get_queryset().perimeter(*args, **kwargs) |
74 | 77 | |
75 | 78 | def point_on_surface(self, *args, **kwargs): |
76 | | return self.get_query_set().point_on_surface(*args, **kwargs) |
| 79 | return self.get_queryset().point_on_surface(*args, **kwargs) |
77 | 80 | |
78 | 81 | def reverse_geom(self, *args, **kwargs): |
79 | | return self.get_query_set().reverse_geom(*args, **kwargs) |
| 82 | return self.get_queryset().reverse_geom(*args, **kwargs) |
80 | 83 | |
81 | 84 | def scale(self, *args, **kwargs): |
82 | | return self.get_query_set().scale(*args, **kwargs) |
| 85 | return self.get_queryset().scale(*args, **kwargs) |
83 | 86 | |
84 | 87 | def snap_to_grid(self, *args, **kwargs): |
85 | | return self.get_query_set().snap_to_grid(*args, **kwargs) |
| 88 | return self.get_queryset().snap_to_grid(*args, **kwargs) |
86 | 89 | |
87 | 90 | def svg(self, *args, **kwargs): |
88 | | return self.get_query_set().svg(*args, **kwargs) |
| 91 | return self.get_queryset().svg(*args, **kwargs) |
89 | 92 | |
90 | 93 | def sym_difference(self, *args, **kwargs): |
91 | | return self.get_query_set().sym_difference(*args, **kwargs) |
| 94 | return self.get_queryset().sym_difference(*args, **kwargs) |
92 | 95 | |
93 | 96 | def transform(self, *args, **kwargs): |
94 | | return self.get_query_set().transform(*args, **kwargs) |
| 97 | return self.get_queryset().transform(*args, **kwargs) |
95 | 98 | |
96 | 99 | def translate(self, *args, **kwargs): |
97 | | return self.get_query_set().translate(*args, **kwargs) |
| 100 | return self.get_queryset().translate(*args, **kwargs) |
98 | 101 | |
99 | 102 | def union(self, *args, **kwargs): |
100 | | return self.get_query_set().union(*args, **kwargs) |
| 103 | return self.get_queryset().union(*args, **kwargs) |
101 | 104 | |
102 | 105 | def unionagg(self, *args, **kwargs): |
103 | | return self.get_query_set().unionagg(*args, **kwargs) |
| 106 | return self.get_queryset().unionagg(*args, **kwargs) |
-
diff --git a/django/contrib/sites/managers.py b/django/contrib/sites/managers.py
index 3df485a..3889e11 100644
a
|
b
|
|
1 | 1 | from django.conf import settings |
2 | 2 | from django.db import models |
3 | 3 | from django.db.models.fields import FieldDoesNotExist |
| 4 | from django.utils.deprecation import deprecated_get_query_set |
4 | 5 | |
| 6 | |
| 7 | @deprecated_get_query_set |
5 | 8 | class CurrentSiteManager(models.Manager): |
6 | 9 | "Use this to limit objects to those associated with the current site." |
7 | 10 | def __init__(self, field_name=None): |
… |
… |
class CurrentSiteManager(models.Manager):
|
35 | 38 | (self.__class__.__name__, self.__field_name, self.model._meta.object_name)) |
36 | 39 | self.__is_validated = True |
37 | 40 | |
38 | | def get_query_set(self): |
| 41 | def get_queryset(self): |
39 | 42 | if not self.__is_validated: |
40 | 43 | self._validate_field_name() |
41 | | return super(CurrentSiteManager, self).get_query_set().filter(**{self.__field_name + '__id__exact': settings.SITE_ID}) |
| 44 | return super(CurrentSiteManager, self).get_queryset().filter(**{self.__field_name + '__id__exact': settings.SITE_ID}) |
-
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index ae792a3..a7e1d11 100644
a
|
b
|
|
1 | 1 | from operator import attrgetter |
2 | 2 | |
| 3 | from django import forms |
| 4 | from django.core import exceptions |
3 | 5 | from django.db import connection, router |
4 | 6 | from django.db.backends import util |
5 | 7 | from django.db.models import signals, get_model |
… |
… |
from django.db.models.query_utils import QueryWrapper
|
11 | 13 | from django.db.models.deletion import CASCADE |
12 | 14 | from django.utils.encoding import smart_text |
13 | 15 | from django.utils import six |
| 16 | from django.utils.deprecation import deprecated_get_query_set |
14 | 17 | from django.utils.translation import ugettext_lazy as _, string_concat |
15 | 18 | from django.utils.functional import curry, cached_property |
16 | | from django.core import exceptions |
17 | | from django import forms |
| 19 | |
18 | 20 | |
19 | 21 | RECURSIVE_RELATIONSHIP_CONSTANT = 'self' |
20 | 22 | |
… |
… |
class RelatedField(object):
|
225 | 227 | return self.rel.related_name or self.opts.object_name.lower() |
226 | 228 | |
227 | 229 | |
| 230 | @deprecated_get_query_set |
228 | 231 | class SingleRelatedObjectDescriptor(object): |
229 | 232 | # This class provides the functionality that makes the related-object |
230 | 233 | # managers available as attributes on a model class, for fields that have |
… |
… |
class SingleRelatedObjectDescriptor(object):
|
238 | 241 | def is_cached(self, instance): |
239 | 242 | return hasattr(instance, self.cache_name) |
240 | 243 | |
241 | | def get_query_set(self, **db_hints): |
| 244 | def get_queryset(self, **db_hints): |
242 | 245 | db = router.db_for_read(self.related.model, **db_hints) |
243 | 246 | return self.related.model._base_manager.using(db) |
244 | 247 | |
… |
… |
class SingleRelatedObjectDescriptor(object):
|
247 | 250 | instance_attr = lambda obj: obj._get_pk_val() |
248 | 251 | instances_dict = dict((instance_attr(inst), inst) for inst in instances) |
249 | 252 | params = {'%s__pk__in' % self.related.field.name: list(instances_dict)} |
250 | | qs = self.get_query_set(instance=instances[0]).filter(**params) |
| 253 | qs = self.get_queryset(instance=instances[0]).filter(**params) |
251 | 254 | # Since we're going to assign directly in the cache, |
252 | 255 | # we must manage the reverse relation cache manually. |
253 | 256 | rel_obj_cache_name = self.related.field.get_cache_name() |
… |
… |
class SingleRelatedObjectDescriptor(object):
|
268 | 271 | else: |
269 | 272 | params = {'%s__pk' % self.related.field.name: related_pk} |
270 | 273 | try: |
271 | | rel_obj = self.get_query_set(instance=instance).get(**params) |
| 274 | rel_obj = self.get_queryset(instance=instance).get(**params) |
272 | 275 | except self.related.model.DoesNotExist: |
273 | 276 | rel_obj = None |
274 | 277 | else: |
… |
… |
class SingleRelatedObjectDescriptor(object):
|
321 | 324 | setattr(value, self.related.field.get_cache_name(), instance) |
322 | 325 | |
323 | 326 | |
| 327 | @deprecated_get_query_set |
324 | 328 | class ReverseSingleRelatedObjectDescriptor(object): |
325 | 329 | # This class provides the functionality that makes the related-object |
326 | 330 | # managers available as attributes on a model class, for fields that have |
… |
… |
class ReverseSingleRelatedObjectDescriptor(object):
|
334 | 338 | def is_cached(self, instance): |
335 | 339 | return hasattr(instance, self.cache_name) |
336 | 340 | |
337 | | def get_query_set(self, **db_hints): |
| 341 | def get_queryset(self, **db_hints): |
338 | 342 | db = router.db_for_read(self.field.rel.to, **db_hints) |
339 | 343 | rel_mgr = self.field.rel.to._default_manager |
340 | 344 | # If the related manager indicates that it should be used for |
… |
… |
class ReverseSingleRelatedObjectDescriptor(object):
|
353 | 357 | params = {'%s__pk__in' % self.field.rel.field_name: list(instances_dict)} |
354 | 358 | else: |
355 | 359 | params = {'%s__in' % self.field.rel.field_name: list(instances_dict)} |
356 | | qs = self.get_query_set(instance=instances[0]).filter(**params) |
| 360 | qs = self.get_queryset(instance=instances[0]).filter(**params) |
357 | 361 | # Since we're going to assign directly in the cache, |
358 | 362 | # we must manage the reverse relation cache manually. |
359 | 363 | if not self.field.rel.multiple: |
… |
… |
class ReverseSingleRelatedObjectDescriptor(object):
|
378 | 382 | params = {'%s__%s' % (self.field.rel.field_name, other_field.rel.field_name): val} |
379 | 383 | else: |
380 | 384 | params = {'%s__exact' % self.field.rel.field_name: val} |
381 | | qs = self.get_query_set(instance=instance) |
| 385 | qs = self.get_queryset(instance=instance) |
382 | 386 | # Assuming the database enforces foreign keys, this won't fail. |
383 | 387 | rel_obj = qs.get(**params) |
384 | 388 | if not self.field.rel.multiple: |
… |
… |
class ForeignRelatedObjectsDescriptor(object):
|
481 | 485 | rel_model = self.related.model |
482 | 486 | attname = rel_field.rel.get_related_field().attname |
483 | 487 | |
| 488 | @deprecated_get_query_set |
484 | 489 | class RelatedManager(superclass): |
485 | 490 | def __init__(self, instance): |
486 | 491 | super(RelatedManager, self).__init__() |
… |
… |
class ForeignRelatedObjectsDescriptor(object):
|
490 | 495 | } |
491 | 496 | self.model = rel_model |
492 | 497 | |
493 | | def get_query_set(self): |
| 498 | def get_queryset(self): |
494 | 499 | try: |
495 | 500 | return self.instance._prefetched_objects_cache[rel_field.related_query_name()] |
496 | 501 | except (AttributeError, KeyError): |
497 | 502 | db = self._db or router.db_for_read(self.model, instance=self.instance) |
498 | | qs = super(RelatedManager, self).get_query_set().using(db).filter(**self.core_filters) |
| 503 | qs = super(RelatedManager, self).get_queryset().using(db).filter(**self.core_filters) |
499 | 504 | if getattr(self.instance, attname) is None: |
500 | 505 | return qs.none() |
501 | 506 | qs._known_related_objects = {rel_field: {self.instance.pk: self.instance}} |
… |
… |
class ForeignRelatedObjectsDescriptor(object):
|
507 | 512 | instances_dict = dict((instance_attr(inst), inst) for inst in instances) |
508 | 513 | db = self._db or router.db_for_read(self.model, instance=instances[0]) |
509 | 514 | query = {'%s__%s__in' % (rel_field.name, attname): list(instances_dict)} |
510 | | qs = super(RelatedManager, self).get_query_set().using(db).filter(**query) |
| 515 | qs = super(RelatedManager, self).get_queryset().using(db).filter(**query) |
511 | 516 | # Since we just bypassed this class' get_query_set(), we must manage |
512 | 517 | # the reverse relation manually. |
513 | 518 | for rel_obj in qs: |
… |
… |
class ForeignRelatedObjectsDescriptor(object):
|
561 | 566 | def create_many_related_manager(superclass, rel): |
562 | 567 | """Creates a manager that subclasses 'superclass' (which is a Manager) |
563 | 568 | and adds behavior for many-to-many related objects.""" |
| 569 | @deprecated_get_query_set |
564 | 570 | class ManyRelatedManager(superclass): |
565 | 571 | def __init__(self, model=None, query_field_name=None, instance=None, symmetrical=None, |
566 | 572 | source_field_name=None, target_field_name=None, reverse=False, |
… |
… |
def create_many_related_manager(superclass, rel):
|
602 | 608 | else: |
603 | 609 | return obj.pk |
604 | 610 | |
605 | | def get_query_set(self): |
| 611 | def get_queryset(self): |
606 | 612 | try: |
607 | 613 | return self.instance._prefetched_objects_cache[self.prefetch_cache_name] |
608 | 614 | except (AttributeError, KeyError): |
609 | 615 | db = self._db or router.db_for_read(self.instance.__class__, instance=self.instance) |
610 | | return super(ManyRelatedManager, self).get_query_set().using(db)._next_is_sticky().filter(**self.core_filters) |
| 616 | return super(ManyRelatedManager, self).get_queryset().using(db)._next_is_sticky().filter(**self.core_filters) |
611 | 617 | |
612 | 618 | def get_prefetch_query_set(self, instances): |
613 | 619 | instance = instances[0] |
… |
… |
def create_many_related_manager(superclass, rel):
|
615 | 621 | db = self._db or router.db_for_read(instance.__class__, instance=instance) |
616 | 622 | query = {'%s__pk__in' % self.query_field_name: |
617 | 623 | set(obj._get_pk_val() for obj in instances)} |
618 | | qs = super(ManyRelatedManager, self).get_query_set().using(db)._next_is_sticky().filter(**query) |
| 624 | qs = super(ManyRelatedManager, self).get_queryset().using(db)._next_is_sticky().filter(**query) |
619 | 625 | |
620 | 626 | # M2M: need to annotate the query in order to get the primary model |
621 | 627 | # that the secondary model was actually related to. We know that |
-
diff --git a/django/db/models/manager.py b/django/db/models/manager.py
index 816f619..91765c3 100644
a
|
b
|
from django.db import router
|
3 | 3 | from django.db.models.query import QuerySet, insert_query, RawQuerySet |
4 | 4 | from django.db.models import signals |
5 | 5 | from django.db.models.fields import FieldDoesNotExist |
| 6 | from django.utils.deprecation import deprecated_get_query_set |
6 | 7 | |
7 | 8 | |
8 | 9 | def ensure_default_manager(sender, **kwargs): |
… |
… |
def ensure_default_manager(sender, **kwargs):
|
47 | 48 | signals.class_prepared.connect(ensure_default_manager) |
48 | 49 | |
49 | 50 | |
| 51 | @deprecated_get_query_set |
50 | 52 | class Manager(object): |
51 | 53 | # Tracks each time a Manager instance is created. Used to retain order. |
52 | 54 | creation_counter = 0 |
… |
… |
class Manager(object):
|
115 | 117 | def get_empty_query_set(self): |
116 | 118 | return QuerySet(self.model, using=self._db).none() |
117 | 119 | |
118 | | def get_query_set(self): |
| 120 | def get_queryset(self): |
119 | 121 | """Returns a new QuerySet object. Subclasses can override this method |
120 | 122 | to easily customize the behavior of the Manager. |
121 | 123 | """ |
… |
… |
class Manager(object):
|
125 | 127 | return self.get_empty_query_set() |
126 | 128 | |
127 | 129 | def all(self): |
128 | | return self.get_query_set() |
| 130 | return self.get_queryset() |
129 | 131 | |
130 | 132 | def count(self): |
131 | | return self.get_query_set().count() |
| 133 | return self.get_queryset().count() |
132 | 134 | |
133 | 135 | def dates(self, *args, **kwargs): |
134 | | return self.get_query_set().dates(*args, **kwargs) |
| 136 | return self.get_queryset().dates(*args, **kwargs) |
135 | 137 | |
136 | 138 | def distinct(self, *args, **kwargs): |
137 | | return self.get_query_set().distinct(*args, **kwargs) |
| 139 | return self.get_queryset().distinct(*args, **kwargs) |
138 | 140 | |
139 | 141 | def extra(self, *args, **kwargs): |
140 | | return self.get_query_set().extra(*args, **kwargs) |
| 142 | return self.get_queryset().extra(*args, **kwargs) |
141 | 143 | |
142 | 144 | def get(self, *args, **kwargs): |
143 | | return self.get_query_set().get(*args, **kwargs) |
| 145 | return self.get_queryset().get(*args, **kwargs) |
144 | 146 | |
145 | 147 | def get_or_create(self, **kwargs): |
146 | | return self.get_query_set().get_or_create(**kwargs) |
| 148 | return self.get_queryset().get_or_create(**kwargs) |
147 | 149 | |
148 | 150 | def create(self, **kwargs): |
149 | | return self.get_query_set().create(**kwargs) |
| 151 | return self.get_queryset().create(**kwargs) |
150 | 152 | |
151 | 153 | def bulk_create(self, *args, **kwargs): |
152 | | return self.get_query_set().bulk_create(*args, **kwargs) |
| 154 | return self.get_queryset().bulk_create(*args, **kwargs) |
153 | 155 | |
154 | 156 | def filter(self, *args, **kwargs): |
155 | | return self.get_query_set().filter(*args, **kwargs) |
| 157 | return self.get_queryset().filter(*args, **kwargs) |
156 | 158 | |
157 | 159 | def aggregate(self, *args, **kwargs): |
158 | | return self.get_query_set().aggregate(*args, **kwargs) |
| 160 | return self.get_queryset().aggregate(*args, **kwargs) |
159 | 161 | |
160 | 162 | def annotate(self, *args, **kwargs): |
161 | | return self.get_query_set().annotate(*args, **kwargs) |
| 163 | return self.get_queryset().annotate(*args, **kwargs) |
162 | 164 | |
163 | 165 | def complex_filter(self, *args, **kwargs): |
164 | | return self.get_query_set().complex_filter(*args, **kwargs) |
| 166 | return self.get_queryset().complex_filter(*args, **kwargs) |
165 | 167 | |
166 | 168 | def exclude(self, *args, **kwargs): |
167 | | return self.get_query_set().exclude(*args, **kwargs) |
| 169 | return self.get_queryset().exclude(*args, **kwargs) |
168 | 170 | |
169 | 171 | def in_bulk(self, *args, **kwargs): |
170 | | return self.get_query_set().in_bulk(*args, **kwargs) |
| 172 | return self.get_queryset().in_bulk(*args, **kwargs) |
171 | 173 | |
172 | 174 | def iterator(self, *args, **kwargs): |
173 | | return self.get_query_set().iterator(*args, **kwargs) |
| 175 | return self.get_queryset().iterator(*args, **kwargs) |
174 | 176 | |
175 | 177 | def earliest(self, *args, **kwargs): |
176 | | return self.get_query_set().earliest(*args, **kwargs) |
| 178 | return self.get_queryset().earliest(*args, **kwargs) |
177 | 179 | |
178 | 180 | def latest(self, *args, **kwargs): |
179 | | return self.get_query_set().latest(*args, **kwargs) |
| 181 | return self.get_queryset().latest(*args, **kwargs) |
180 | 182 | |
181 | 183 | def order_by(self, *args, **kwargs): |
182 | | return self.get_query_set().order_by(*args, **kwargs) |
| 184 | return self.get_queryset().order_by(*args, **kwargs) |
183 | 185 | |
184 | 186 | def select_for_update(self, *args, **kwargs): |
185 | | return self.get_query_set().select_for_update(*args, **kwargs) |
| 187 | return self.get_queryset().select_for_update(*args, **kwargs) |
186 | 188 | |
187 | 189 | def select_related(self, *args, **kwargs): |
188 | | return self.get_query_set().select_related(*args, **kwargs) |
| 190 | return self.get_queryset().select_related(*args, **kwargs) |
189 | 191 | |
190 | 192 | def prefetch_related(self, *args, **kwargs): |
191 | | return self.get_query_set().prefetch_related(*args, **kwargs) |
| 193 | return self.get_queryset().prefetch_related(*args, **kwargs) |
192 | 194 | |
193 | 195 | def values(self, *args, **kwargs): |
194 | | return self.get_query_set().values(*args, **kwargs) |
| 196 | return self.get_queryset().values(*args, **kwargs) |
195 | 197 | |
196 | 198 | def values_list(self, *args, **kwargs): |
197 | | return self.get_query_set().values_list(*args, **kwargs) |
| 199 | return self.get_queryset().values_list(*args, **kwargs) |
198 | 200 | |
199 | 201 | def update(self, *args, **kwargs): |
200 | | return self.get_query_set().update(*args, **kwargs) |
| 202 | return self.get_queryset().update(*args, **kwargs) |
201 | 203 | |
202 | 204 | def reverse(self, *args, **kwargs): |
203 | | return self.get_query_set().reverse(*args, **kwargs) |
| 205 | return self.get_queryset().reverse(*args, **kwargs) |
204 | 206 | |
205 | 207 | def defer(self, *args, **kwargs): |
206 | | return self.get_query_set().defer(*args, **kwargs) |
| 208 | return self.get_queryset().defer(*args, **kwargs) |
207 | 209 | |
208 | 210 | def only(self, *args, **kwargs): |
209 | | return self.get_query_set().only(*args, **kwargs) |
| 211 | return self.get_queryset().only(*args, **kwargs) |
210 | 212 | |
211 | 213 | def using(self, *args, **kwargs): |
212 | | return self.get_query_set().using(*args, **kwargs) |
| 214 | return self.get_queryset().using(*args, **kwargs) |
213 | 215 | |
214 | 216 | def exists(self, *args, **kwargs): |
215 | | return self.get_query_set().exists(*args, **kwargs) |
| 217 | return self.get_queryset().exists(*args, **kwargs) |
216 | 218 | |
217 | 219 | def _insert(self, objs, fields, **kwargs): |
218 | 220 | return insert_query(self.model, objs, fields, **kwargs) |
219 | 221 | |
220 | 222 | def _update(self, values, **kwargs): |
221 | | return self.get_query_set()._update(values, **kwargs) |
| 223 | return self.get_queryset()._update(values, **kwargs) |
222 | 224 | |
223 | 225 | def raw(self, raw_query, params=None, *args, **kwargs): |
224 | 226 | return RawQuerySet(raw_query=raw_query, model=self.model, params=params, using=self._db, *args, **kwargs) |
… |
… |
class SwappedManagerDescriptor(object):
|
260 | 262 | )) |
261 | 263 | |
262 | 264 | |
| 265 | @deprecated_get_query_set |
263 | 266 | class EmptyManager(Manager): |
264 | 267 | def __init__(self, model): |
265 | 268 | super(EmptyManager, self).__init__() |
266 | 269 | self.model = model |
267 | 270 | |
268 | | def get_query_set(self): |
| 271 | def get_queryset(self): |
269 | 272 | return self.get_empty_query_set() |
-
diff --git a/django/forms/models.py b/django/forms/models.py
index 837da74..fa27bb0 100644
a
|
b
|
class BaseModelFormSet(BaseFormSet):
|
479 | 479 | if self.queryset is not None: |
480 | 480 | qs = self.queryset |
481 | 481 | else: |
482 | | qs = self.model._default_manager.get_query_set() |
| 482 | qs = self.model._default_manager.get_queryset() |
483 | 483 | |
484 | 484 | # If the queryset isn't already ordered we need to add an |
485 | 485 | # artificial ordering here to make sure that all formsets |
… |
… |
class BaseModelFormSet(BaseFormSet):
|
674 | 674 | except IndexError: |
675 | 675 | pk_value = None |
676 | 676 | if isinstance(pk, OneToOneField) or isinstance(pk, ForeignKey): |
677 | | qs = pk.rel.to._default_manager.get_query_set() |
| 677 | qs = pk.rel.to._default_manager.get_queryset() |
678 | 678 | else: |
679 | | qs = self.model._default_manager.get_query_set() |
| 679 | qs = self.model._default_manager.get_queryset() |
680 | 680 | qs = qs.using(form.instance._state.db) |
681 | 681 | form.fields[self._pk_field.name] = ModelChoiceField(qs, initial=pk_value, required=False, widget=HiddenInput) |
682 | 682 | super(BaseModelFormSet, self).add_fields(form, index) |
-
diff --git a/django/utils/deprecation.py b/django/utils/deprecation.py
new file mode 100644
index 0000000..6f93325
-
|
+
|
|
| 1 | from __future__ import unicode_literals |
| 2 | import warnings |
| 3 | |
| 4 | |
| 5 | def deprecated_get_query_set(cls): |
| 6 | """ |
| 7 | A class decorator that raises a warning when `get_query_set` is called |
| 8 | instead of `get_queryset`. |
| 9 | """ |
| 10 | def get_query_set(self, *args, **kwargs): |
| 11 | warnings.warn( |
| 12 | ('`%s.get_query_set` is deprecated, use `get_queryset` instead.' % cls.__name__), |
| 13 | PendingDeprecationWarning, 2) |
| 14 | return cls.get_queryset(self, *args, **kwargs) |
| 15 | cls.get_query_set = get_query_set |
| 16 | return cls |
| 17 | No newline at end of file |
-
diff --git a/tests/modeltests/custom_managers/models.py b/tests/modeltests/custom_managers/models.py
index de7c177..2f5e62f 100644
a
|
b
|
class Person(models.Model):
|
30 | 30 | def __str__(self): |
31 | 31 | return "%s %s" % (self.first_name, self.last_name) |
32 | 32 | |
33 | | # An example of a custom manager that sets get_query_set(). |
| 33 | # An example of a custom manager that sets get_queryset(). |
34 | 34 | |
35 | 35 | class PublishedBookManager(models.Manager): |
36 | | def get_query_set(self): |
37 | | return super(PublishedBookManager, self).get_query_set().filter(is_published=True) |
| 36 | def get_queryset(self): |
| 37 | return super(PublishedBookManager, self).get_queryset().filter(is_published=True) |
38 | 38 | |
39 | 39 | @python_2_unicode_compatible |
40 | 40 | class Book(models.Model): |
… |
… |
class Book(models.Model):
|
50 | 50 | # An example of providing multiple custom managers. |
51 | 51 | |
52 | 52 | class FastCarManager(models.Manager): |
53 | | def get_query_set(self): |
54 | | return super(FastCarManager, self).get_query_set().filter(top_speed__gt=150) |
| 53 | def get_queryset(self): |
| 54 | return super(FastCarManager, self).get_queryset().filter(top_speed__gt=150) |
55 | 55 | |
56 | 56 | @python_2_unicode_compatible |
57 | 57 | class Car(models.Model): |
-
diff --git a/tests/modeltests/fixtures/models.py b/tests/modeltests/fixtures/models.py
index 8bd3501..976716f 100644
a
|
b
|
class Person(models.Model):
|
78 | 78 | return (self.name,) |
79 | 79 | |
80 | 80 | class SpyManager(PersonManager): |
81 | | def get_query_set(self): |
82 | | return super(SpyManager, self).get_query_set().filter(cover_blown=False) |
| 81 | def get_queryset(self): |
| 82 | return super(SpyManager, self).get_queryset().filter(cover_blown=False) |
83 | 83 | |
84 | 84 | class Spy(Person): |
85 | 85 | objects = SpyManager() |
-
diff --git a/tests/modeltests/generic_relations/models.py b/tests/modeltests/generic_relations/models.py
index 18d7623..34dc8d3 100644
a
|
b
|
class Mineral(models.Model):
|
88 | 88 | return self.name |
89 | 89 | |
90 | 90 | class GeckoManager(models.Manager): |
91 | | def get_query_set(self): |
92 | | return super(GeckoManager, self).get_query_set().filter(has_tail=True) |
| 91 | def get_queryset(self): |
| 92 | return super(GeckoManager, self).get_queryset().filter(has_tail=True) |
93 | 93 | |
94 | 94 | class Gecko(models.Model): |
95 | 95 | has_tail = models.BooleanField() |
-
diff --git a/tests/modeltests/get_object_or_404/models.py b/tests/modeltests/get_object_or_404/models.py
index bda0605..bb9aa60 100644
a
|
b
|
class Author(models.Model):
|
22 | 22 | return self.name |
23 | 23 | |
24 | 24 | class ArticleManager(models.Manager): |
25 | | def get_query_set(self): |
26 | | return super(ArticleManager, self).get_query_set().filter(authors__name__icontains='sir') |
| 25 | def get_queryset(self): |
| 26 | return super(ArticleManager, self).get_queryset().filter(authors__name__icontains='sir') |
27 | 27 | |
28 | 28 | @python_2_unicode_compatible |
29 | 29 | class Article(models.Model): |
-
diff --git a/tests/modeltests/prefetch_related/models.py b/tests/modeltests/prefetch_related/models.py
index e58997d..81c5698 100644
a
|
b
|
class Qualification(models.Model):
|
87 | 87 | |
88 | 88 | |
89 | 89 | class TeacherManager(models.Manager): |
90 | | def get_query_set(self): |
91 | | return super(TeacherManager, self).get_query_set().prefetch_related('qualifications') |
| 90 | def get_queryset(self): |
| 91 | return super(TeacherManager, self).get_queryset().prefetch_related('qualifications') |
92 | 92 | |
93 | 93 | |
94 | 94 | @python_2_unicode_compatible |
-
diff --git a/tests/modeltests/proxy_models/models.py b/tests/modeltests/proxy_models/models.py
index 6c962aa..ffb3665 100644
a
|
b
|
from django.utils.encoding import python_2_unicode_compatible
|
10 | 10 | # A couple of managers for testing managing overriding in proxy model cases. |
11 | 11 | |
12 | 12 | class PersonManager(models.Manager): |
13 | | def get_query_set(self): |
14 | | return super(PersonManager, self).get_query_set().exclude(name="fred") |
| 13 | def get_queryset(self): |
| 14 | return super(PersonManager, self).get_queryset().exclude(name="fred") |
15 | 15 | |
16 | 16 | class SubManager(models.Manager): |
17 | | def get_query_set(self): |
18 | | return super(SubManager, self).get_query_set().exclude(name="wilma") |
| 17 | def get_queryset(self): |
| 18 | return super(SubManager, self).get_queryset().exclude(name="wilma") |
19 | 19 | |
20 | 20 | @python_2_unicode_compatible |
21 | 21 | class Person(models.Model): |
-
diff --git a/tests/regressiontests/admin_changelist/models.py b/tests/regressiontests/admin_changelist/models.py
index 4ba2f9c..786b438 100644
a
|
b
|
class UnorderedObject(models.Model):
|
74 | 74 | |
75 | 75 | |
76 | 76 | class OrderedObjectManager(models.Manager): |
77 | | def get_query_set(self): |
78 | | return super(OrderedObjectManager, self).get_query_set().order_by('number') |
| 77 | def get_queryset(self): |
| 78 | return super(OrderedObjectManager, self).get_queryset().order_by('number') |
79 | 79 | |
80 | 80 | class OrderedObject(models.Model): |
81 | 81 | """ |
-
diff --git a/tests/regressiontests/admin_changelist/tests.py b/tests/regressiontests/admin_changelist/tests.py
index 7a3a5c0..2f94cc7 100644
a
|
b
|
class ChangeListTests(TestCase):
|
39 | 39 | |
40 | 40 | def test_select_related_preserved(self): |
41 | 41 | """ |
42 | | Regression test for #10348: ChangeList.get_query_set() shouldn't |
| 42 | Regression test for #10348: ChangeList.get_queryset() shouldn't |
43 | 43 | overwrite a custom select_related provided by ModelAdmin.queryset(). |
44 | 44 | """ |
45 | 45 | m = ChildAdmin(Child, admin.site) |
-
diff --git a/tests/regressiontests/admin_filters/tests.py b/tests/regressiontests/admin_filters/tests.py
index 11f792e..d25c8f4 100644
a
|
b
|
class ListFiltersTests(TestCase):
|
183 | 183 | changelist = self.get_changelist(request, Book, modeladmin) |
184 | 184 | |
185 | 185 | # Make sure the correct queryset is returned |
186 | | queryset = changelist.get_query_set(request) |
| 186 | queryset = changelist.get_queryset(request) |
187 | 187 | self.assertEqual(list(queryset), [self.django_book, self.djangonaut_book]) |
188 | 188 | |
189 | 189 | # Make sure the correct choice is selected |
… |
… |
class ListFiltersTests(TestCase):
|
200 | 200 | changelist = self.get_changelist(request, Book, modeladmin) |
201 | 201 | |
202 | 202 | # Make sure the correct queryset is returned |
203 | | queryset = changelist.get_query_set(request) |
| 203 | queryset = changelist.get_queryset(request) |
204 | 204 | if (self.today.year, self.today.month) == (self.one_week_ago.year, self.one_week_ago.month): |
205 | 205 | # In case one week ago is in the same month. |
206 | 206 | self.assertEqual(list(queryset), [self.gipsy_book, self.django_book, self.djangonaut_book]) |
… |
… |
class ListFiltersTests(TestCase):
|
221 | 221 | changelist = self.get_changelist(request, Book, modeladmin) |
222 | 222 | |
223 | 223 | # Make sure the correct queryset is returned |
224 | | queryset = changelist.get_query_set(request) |
| 224 | queryset = changelist.get_queryset(request) |
225 | 225 | if self.today.year == self.one_week_ago.year: |
226 | 226 | # In case one week ago is in the same year. |
227 | 227 | self.assertEqual(list(queryset), [self.gipsy_book, self.django_book, self.djangonaut_book]) |
… |
… |
class ListFiltersTests(TestCase):
|
242 | 242 | changelist = self.get_changelist(request, Book, modeladmin) |
243 | 243 | |
244 | 244 | # Make sure the correct queryset is returned |
245 | | queryset = changelist.get_query_set(request) |
| 245 | queryset = changelist.get_queryset(request) |
246 | 246 | self.assertEqual(list(queryset), [self.gipsy_book, self.django_book, self.djangonaut_book]) |
247 | 247 | |
248 | 248 | # Make sure the correct choice is selected |
… |
… |
class ListFiltersTests(TestCase):
|
266 | 266 | changelist = self.get_changelist(request, Book, modeladmin) |
267 | 267 | |
268 | 268 | # Make sure the correct queryset is returned |
269 | | queryset = changelist.get_query_set(request) |
| 269 | queryset = changelist.get_queryset(request) |
270 | 270 | self.assertEqual(list(queryset), [self.django_book]) |
271 | 271 | |
272 | 272 | # Make sure the last choice is None and is selected |
… |
… |
class ListFiltersTests(TestCase):
|
293 | 293 | changelist = self.get_changelist(request, Book, modeladmin) |
294 | 294 | |
295 | 295 | # Make sure the correct queryset is returned |
296 | | queryset = changelist.get_query_set(request) |
| 296 | queryset = changelist.get_queryset(request) |
297 | 297 | self.assertEqual(list(queryset), [self.gipsy_book]) |
298 | 298 | |
299 | 299 | # Make sure the last choice is None and is selected |
… |
… |
class ListFiltersTests(TestCase):
|
321 | 321 | changelist = self.get_changelist(request, Book, modeladmin) |
322 | 322 | |
323 | 323 | # Make sure the correct queryset is returned |
324 | | queryset = changelist.get_query_set(request) |
| 324 | queryset = changelist.get_queryset(request) |
325 | 325 | self.assertEqual(list(queryset), [self.django_book, self.bio_book, self.djangonaut_book]) |
326 | 326 | |
327 | 327 | # Make sure the last choice is None and is selected |
… |
… |
class ListFiltersTests(TestCase):
|
349 | 349 | changelist = self.get_changelist(request, User, modeladmin) |
350 | 350 | |
351 | 351 | # Make sure the correct queryset is returned |
352 | | queryset = changelist.get_query_set(request) |
| 352 | queryset = changelist.get_queryset(request) |
353 | 353 | self.assertEqual(list(queryset), [self.lisa]) |
354 | 354 | |
355 | 355 | # Make sure the last choice is None and is selected |
… |
… |
class ListFiltersTests(TestCase):
|
374 | 374 | changelist = self.get_changelist(request, User, modeladmin) |
375 | 375 | |
376 | 376 | # Make sure the correct queryset is returned |
377 | | queryset = changelist.get_query_set(request) |
| 377 | queryset = changelist.get_queryset(request) |
378 | 378 | self.assertEqual(list(queryset), [self.alfred]) |
379 | 379 | |
380 | 380 | # Make sure the last choice is None and is selected |
… |
… |
class ListFiltersTests(TestCase):
|
410 | 410 | changelist = self.get_changelist(request, Book, modeladmin) |
411 | 411 | |
412 | 412 | # Make sure the correct queryset is returned |
413 | | queryset = changelist.get_query_set(request) |
| 413 | queryset = changelist.get_queryset(request) |
414 | 414 | self.assertEqual(list(queryset), [self.bio_book]) |
415 | 415 | |
416 | 416 | # Make sure the correct choice is selected |
… |
… |
class ListFiltersTests(TestCase):
|
424 | 424 | changelist = self.get_changelist(request, Book, modeladmin) |
425 | 425 | |
426 | 426 | # Make sure the correct queryset is returned |
427 | | queryset = changelist.get_query_set(request) |
| 427 | queryset = changelist.get_queryset(request) |
428 | 428 | self.assertEqual(list(queryset), [self.gipsy_book, self.djangonaut_book]) |
429 | 429 | |
430 | 430 | # Make sure the correct choice is selected |
… |
… |
class ListFiltersTests(TestCase):
|
438 | 438 | changelist = self.get_changelist(request, Book, modeladmin) |
439 | 439 | |
440 | 440 | # Make sure the correct queryset is returned |
441 | | queryset = changelist.get_query_set(request) |
| 441 | queryset = changelist.get_queryset(request) |
442 | 442 | self.assertEqual(list(queryset), [self.django_book]) |
443 | 443 | |
444 | 444 | # Make sure the correct choice is selected |
… |
… |
class ListFiltersTests(TestCase):
|
457 | 457 | changelist = self.get_changelist(request, Book, modeladmin) |
458 | 458 | |
459 | 459 | # Make sure the correct queryset is returned |
460 | | queryset = changelist.get_query_set(request) |
| 460 | queryset = changelist.get_queryset(request) |
461 | 461 | self.assertEqual(list(queryset), list(Book.objects.all().order_by('-id'))) |
462 | 462 | |
463 | 463 | # Make sure the correct choice is selected |
… |
… |
class ListFiltersTests(TestCase):
|
474 | 474 | changelist = self.get_changelist(request, Book, modeladmin) |
475 | 475 | |
476 | 476 | # Make sure the correct queryset is returned |
477 | | queryset = changelist.get_query_set(request) |
| 477 | queryset = changelist.get_queryset(request) |
478 | 478 | self.assertEqual(list(queryset), []) |
479 | 479 | |
480 | 480 | # Make sure the correct choice is selected |
… |
… |
class ListFiltersTests(TestCase):
|
491 | 491 | changelist = self.get_changelist(request, Book, modeladmin) |
492 | 492 | |
493 | 493 | # Make sure the correct queryset is returned |
494 | | queryset = changelist.get_query_set(request) |
| 494 | queryset = changelist.get_queryset(request) |
495 | 495 | self.assertEqual(list(queryset), [self.bio_book]) |
496 | 496 | |
497 | 497 | # Make sure the correct choice is selected |
… |
… |
class ListFiltersTests(TestCase):
|
508 | 508 | changelist = self.get_changelist(request, Book, modeladmin) |
509 | 509 | |
510 | 510 | # Make sure the correct queryset is returned |
511 | | queryset = changelist.get_query_set(request) |
| 511 | queryset = changelist.get_queryset(request) |
512 | 512 | self.assertEqual(list(queryset), [self.gipsy_book, self.djangonaut_book]) |
513 | 513 | |
514 | 514 | # Make sure the correct choice is selected |
… |
… |
class ListFiltersTests(TestCase):
|
525 | 525 | changelist = self.get_changelist(request, Book, modeladmin) |
526 | 526 | |
527 | 527 | # Make sure the correct queryset is returned |
528 | | queryset = changelist.get_query_set(request) |
| 528 | queryset = changelist.get_queryset(request) |
529 | 529 | self.assertEqual(list(queryset), [self.djangonaut_book]) |
530 | 530 | |
531 | 531 | # Make sure the correct choices are selected |
… |
… |
class ListFiltersTests(TestCase):
|
615 | 615 | changelist = self.get_changelist(request, Book, modeladmin) |
616 | 616 | |
617 | 617 | # Make sure the correct queryset is returned |
618 | | queryset = changelist.get_query_set(request) |
| 618 | queryset = changelist.get_queryset(request) |
619 | 619 | self.assertEqual(list(queryset), [self.bio_book]) |
620 | 620 | |
621 | 621 | filterspec = changelist.get_filters(request)[0][-1] |
… |
… |
class ListFiltersTests(TestCase):
|
637 | 637 | changelist = self.get_changelist(request, Book, modeladmin) |
638 | 638 | |
639 | 639 | # Make sure the correct queryset is returned |
640 | | queryset = changelist.get_query_set(request) |
| 640 | queryset = changelist.get_queryset(request) |
641 | 641 | self.assertEqual(list(queryset), [self.bio_book]) |
642 | 642 | |
643 | 643 | # Make sure the correct choice is selected |
… |
… |
class ListFiltersTests(TestCase):
|
654 | 654 | changelist = self.get_changelist(request, Book, modeladmin) |
655 | 655 | |
656 | 656 | # Make sure the correct queryset is returned |
657 | | queryset = changelist.get_query_set(request) |
| 657 | queryset = changelist.get_queryset(request) |
658 | 658 | self.assertEqual(list(queryset), [self.bio_book]) |
659 | 659 | |
660 | 660 | # Make sure the correct choice is selected |
… |
… |
class ListFiltersTests(TestCase):
|
676 | 676 | request = self.request_factory.get('/', {'department': self.john.pk}) |
677 | 677 | changelist = self.get_changelist(request, Employee, modeladmin) |
678 | 678 | |
679 | | queryset = changelist.get_query_set(request) |
| 679 | queryset = changelist.get_queryset(request) |
680 | 680 | |
681 | 681 | self.assertEqual(list(queryset), [self.john]) |
682 | 682 | |
… |
… |
class ListFiltersTests(TestCase):
|
698 | 698 | changelist = self.get_changelist(request, Employee, modeladmin) |
699 | 699 | |
700 | 700 | # Make sure the correct queryset is returned |
701 | | queryset = changelist.get_query_set(request) |
| 701 | queryset = changelist.get_queryset(request) |
702 | 702 | self.assertEqual(list(queryset), [self.jack, self.john]) |
703 | 703 | |
704 | 704 | filterspec = changelist.get_filters(request)[0][-1] |
… |
… |
class ListFiltersTests(TestCase):
|
723 | 723 | changelist = self.get_changelist(request, Employee, modeladmin) |
724 | 724 | |
725 | 725 | # Make sure the correct queryset is returned |
726 | | queryset = changelist.get_query_set(request) |
| 726 | queryset = changelist.get_queryset(request) |
727 | 727 | self.assertEqual(list(queryset), [self.john]) |
728 | 728 | |
729 | 729 | filterspec = changelist.get_filters(request)[0][-1] |
-
diff --git a/tests/regressiontests/admin_views/admin.py b/tests/regressiontests/admin_views/admin.py
index 435883e..2d85e54 100644
a
|
b
|
class PostAdmin(admin.ModelAdmin):
|
417 | 417 | |
418 | 418 | |
419 | 419 | class CustomChangeList(ChangeList): |
420 | | def get_query_set(self, request): |
| 420 | def get_queryset(self, request): |
421 | 421 | return self.root_query_set.filter(pk=9999) # Does not exist |
422 | 422 | |
423 | 423 | |
-
diff --git a/tests/regressiontests/admin_widgets/models.py b/tests/regressiontests/admin_widgets/models.py
index 2977b86..ae19d58 100644
a
|
b
|
class Album(models.Model):
|
37 | 37 | return self.name |
38 | 38 | |
39 | 39 | class HiddenInventoryManager(models.Manager): |
40 | | def get_query_set(self): |
41 | | return super(HiddenInventoryManager, self).get_query_set().filter(hidden=False) |
| 40 | def get_queryset(self): |
| 41 | return super(HiddenInventoryManager, self).get_queryset().filter(hidden=False) |
42 | 42 | |
43 | 43 | @python_2_unicode_compatible |
44 | 44 | class Inventory(models.Model): |
-
diff --git a/tests/regressiontests/custom_managers_regress/models.py b/tests/regressiontests/custom_managers_regress/models.py
index 71073f0..95cf6e8 100644
a
|
b
|
class RestrictedManager(models.Manager):
|
10 | 10 | """ |
11 | 11 | A manager that filters out non-public instances. |
12 | 12 | """ |
13 | | def get_query_set(self): |
14 | | return super(RestrictedManager, self).get_query_set().filter(is_public=True) |
| 13 | def get_queryset(self): |
| 14 | return super(RestrictedManager, self).get_queryset().filter(is_public=True) |
15 | 15 | |
16 | 16 | @python_2_unicode_compatible |
17 | 17 | class RelatedModel(models.Model): |
-
diff --git a/tests/regressiontests/managers_regress/models.py b/tests/regressiontests/managers_regress/models.py
index d72970d..d8dd22e 100644
a
|
b
|
from django.utils.encoding import python_2_unicode_compatible
|
7 | 7 | |
8 | 8 | |
9 | 9 | class OnlyFred(models.Manager): |
10 | | def get_query_set(self): |
11 | | return super(OnlyFred, self).get_query_set().filter(name='fred') |
| 10 | def get_queryset(self): |
| 11 | return super(OnlyFred, self).get_queryset().filter(name='fred') |
12 | 12 | |
13 | 13 | |
14 | 14 | class OnlyBarney(models.Manager): |
15 | | def get_query_set(self): |
16 | | return super(OnlyBarney, self).get_query_set().filter(name='barney') |
| 15 | def get_queryset(self): |
| 16 | return super(OnlyBarney, self).get_queryset().filter(name='barney') |
17 | 17 | |
18 | 18 | |
19 | 19 | class Value42(models.Manager): |
20 | | def get_query_set(self): |
21 | | return super(Value42, self).get_query_set().filter(value=42) |
| 20 | def get_queryset(self): |
| 21 | return super(Value42, self).get_queryset().filter(value=42) |
22 | 22 | |
23 | 23 | |
24 | 24 | class AbstractBase1(models.Model): |
-
diff --git a/tests/regressiontests/modeladmin/tests.py b/tests/regressiontests/modeladmin/tests.py
index b0a1812..2f3eddd 100644
a
|
b
|
class ValidationTests(unittest.TestCase):
|
1074 | 1074 | return 'awesomeness' |
1075 | 1075 | def get_choices(self, request): |
1076 | 1076 | return (('bit', 'A bit awesome'), ('very', 'Very awesome'), ) |
1077 | | def get_query_set(self, cl, qs): |
| 1077 | def get_queryset(self, cl, qs): |
1078 | 1078 | return qs |
1079 | 1079 | |
1080 | 1080 | class ValidationTestModelAdmin(ModelAdmin): |
-
diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
index 16583e8..7489aeb 100644
a
|
b
|
class LoopZ(models.Model):
|
175 | 175 | |
176 | 176 | # A model and custom default manager combination. |
177 | 177 | class CustomManager(models.Manager): |
178 | | def get_query_set(self): |
179 | | qs = super(CustomManager, self).get_query_set() |
| 178 | def get_queryset(self): |
| 179 | qs = super(CustomManager, self).get_queryset() |
180 | 180 | return qs.filter(public=True, tag__name='t1') |
181 | 181 | |
182 | 182 | @python_2_unicode_compatible |
… |
… |
class Detail(models.Model):
|
196 | 196 | data = models.CharField(max_length=10) |
197 | 197 | |
198 | 198 | class MemberManager(models.Manager): |
199 | | def get_query_set(self): |
200 | | return super(MemberManager, self).get_query_set().select_related("details") |
| 199 | def get_queryset(self): |
| 200 | return super(MemberManager, self).get_queryset().select_related("details") |
201 | 201 | |
202 | 202 | class Member(models.Model): |
203 | 203 | name = models.CharField(max_length=10) |
-
diff --git a/tests/regressiontests/reverse_single_related/models.py b/tests/regressiontests/reverse_single_related/models.py
index 898be84..30ba345 100644
a
|
b
|
from django.db import models
|
2 | 2 | |
3 | 3 | |
4 | 4 | class SourceManager(models.Manager): |
5 | | def get_query_set(self): |
6 | | return super(SourceManager, self).get_query_set().filter(is_public=True) |
| 5 | def get_queryset(self): |
| 6 | return super(SourceManager, self).get_queryset().filter(is_public=True) |
7 | 7 | |
8 | 8 | class Source(models.Model): |
9 | 9 | is_public = models.BooleanField() |