Ticket #15363: ticket-15363-normalize-get_queryset.patch​

File ticket-15363-normalize-get_queryset.patch​, 92.0 KB (added by loic84, 12 years ago)
Line 
1diff --git a/AUTHORS b/AUTHORS
2index c603833..0ee3618 100644
3--- a/AUTHORS
4+++ b/AUTHORS
5@@ -98,6 +98,7 @@ answer newbie questions, and generally made Django that much better:
6 Natalia Bidart <nataliabidart@gmail.com>
7 Mark Biggers <biggers@utsl.com>
8 Paul Bissex <http://e-scribe.com/>
9+ Loïc Bistuer <loic.bistuer@gmail.com>
10 Simon Blanchard
11 Craig Blaszczyk <masterjakul@gmail.com>
12 David Blewett <david@dawninglight.net>
13diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
14index ff7873b..37b2157 100644
15--- a/django/contrib/admin/options.py
16+++ b/django/contrib/admin/options.py
17@@ -28,6 +28,7 @@ from django.utils.datastructures import SortedDict
18 from django.utils.html import escape, escapejs
19 from django.utils.safestring import mark_safe
20 from django.utils import six
21+from django.utils.deprecation import RenameMethodsBase
22 from django.utils.text import capfirst, get_text_list
23 from django.utils.translation import ugettext as _
24 from django.utils.translation import ungettext
25@@ -63,7 +64,13 @@ FORMFIELD_FOR_DBFIELD_DEFAULTS = {
26 csrf_protect_m = method_decorator(csrf_protect)
27
28
29-class BaseModelAdmin(six.with_metaclass(forms.MediaDefiningClass)):
30+class RenameBaseModelAdminMethods(forms.MediaDefiningClass, RenameMethodsBase):
31+ renamed_methods = (
32+ ('queryset', 'get_queryset'),
33+ )
34+
35+
36+class BaseModelAdmin(six.with_metaclass(RenameBaseModelAdminMethods)):
37 """Functionality common to both ModelAdmin and InlineAdmin."""
38
39 raw_id_fields = ()
40@@ -217,12 +224,12 @@ class BaseModelAdmin(six.with_metaclass(forms.MediaDefiningClass)):
41 """
42 return self.prepopulated_fields
43
44- def queryset(self, request):
45+ def get_queryset(self, request):
46 """
47 Returns a QuerySet of all model instances that can be edited by the
48 admin site. This is used by changelist_view.
49 """
50- qs = self.model._default_manager.get_query_set()
51+ qs = self.model._default_manager.get_queryset()
52 # TODO: this should be handled by some parameter to the ChangeList.
53 ordering = self.get_ordering(request)
54 if ordering:
55@@ -474,7 +481,7 @@ class ModelAdmin(BaseModelAdmin):
56 returned if no match is found (or the object_id failed validation
57 against the primary key field).
58 """
59- queryset = self.queryset(request)
60+ queryset = self.get_queryset(request)
61 model = queryset.model
62 try:
63 object_id = model._meta.pk.to_python(object_id)
64@@ -986,7 +993,7 @@ class ModelAdmin(BaseModelAdmin):
65 formset = FormSet(data=request.POST, files=request.FILES,
66 instance=new_object,
67 save_as_new="_saveasnew" in request.POST,
68- prefix=prefix, queryset=inline.queryset(request))
69+ prefix=prefix, queryset=inline.get_queryset(request))
70 formsets.append(formset)
71 if all_valid(formsets) and form_validated:
72 self.save_model(request, new_object, form, False)
73@@ -1012,7 +1019,7 @@ class ModelAdmin(BaseModelAdmin):
74 if prefixes[prefix] != 1 or not prefix:
75 prefix = "%s-%s" % (prefix, prefixes[prefix])
76 formset = FormSet(instance=self.model(), prefix=prefix,
77- queryset=inline.queryset(request))
78+ queryset=inline.get_queryset(request))
79 formsets.append(formset)
80
81 adminForm = helpers.AdminForm(form, list(self.get_fieldsets(request)),
82@@ -1082,7 +1089,7 @@ class ModelAdmin(BaseModelAdmin):
83 prefix = "%s-%s" % (prefix, prefixes[prefix])
84 formset = FormSet(request.POST, request.FILES,
85 instance=new_object, prefix=prefix,
86- queryset=inline.queryset(request))
87+ queryset=inline.get_queryset(request))
88
89 formsets.append(formset)
90
91@@ -1102,7 +1109,7 @@ class ModelAdmin(BaseModelAdmin):
92 if prefixes[prefix] != 1 or not prefix:
93 prefix = "%s-%s" % (prefix, prefixes[prefix])
94 formset = FormSet(instance=obj, prefix=prefix,
95- queryset=inline.queryset(request))
96+ queryset=inline.get_queryset(request))
97 formsets.append(formset)
98
99 adminForm = helpers.AdminForm(form, self.get_fieldsets(request, obj),
100@@ -1187,7 +1194,7 @@ class ModelAdmin(BaseModelAdmin):
101 if (actions and request.method == 'POST' and
102 'index' in request.POST and '_save' not in request.POST):
103 if selected:
104- response = self.response_action(request, queryset=cl.get_query_set(request))
105+ response = self.response_action(request, queryset=cl.get_queryset(request))
106 if response:
107 return response
108 else:
109@@ -1203,7 +1210,7 @@ class ModelAdmin(BaseModelAdmin):
110 helpers.ACTION_CHECKBOX_NAME in request.POST and
111 'index' not in request.POST and '_save' not in request.POST):
112 if selected:
113- response = self.response_action(request, queryset=cl.get_query_set(request))
114+ response = self.response_action(request, queryset=cl.get_queryset(request))
115 if response:
116 return response
117 else:
118@@ -1462,8 +1469,8 @@ class InlineModelAdmin(BaseModelAdmin):
119 fields = list(form.base_fields) + list(self.get_readonly_fields(request, obj))
120 return [(None, {'fields': fields})]
121
122- def queryset(self, request):
123- queryset = super(InlineModelAdmin, self).queryset(request)
124+ def get_queryset(self, request):
125+ queryset = super(InlineModelAdmin, self).get_queryset(request)
126 if not self.has_change_permission(request):
127 queryset = queryset.none()
128 return queryset
129diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py
130index 8bda323..3757436 100644
131--- a/django/contrib/admin/views/main.py
132+++ b/django/contrib/admin/views/main.py
133@@ -6,7 +6,9 @@ from django.core.paginator import InvalidPage
134 from django.core.urlresolvers import reverse
135 from django.db import models
136 from django.db.models.fields import FieldDoesNotExist
137+from django.utils import six
138 from django.utils.datastructures import SortedDict
139+from django.utils.deprecation import RenameMethodsBase
140 from django.utils.encoding import force_str, force_text
141 from django.utils.translation import ugettext, ugettext_lazy
142 from django.utils.http import urlencode
143@@ -33,14 +35,20 @@ IGNORED_PARAMS = (
144 EMPTY_CHANGELIST_VALUE = ugettext_lazy('(None)')
145
146
147-class ChangeList(object):
148+class RenameChangeListMethods(RenameMethodsBase):
149+ renamed_methods = (
150+ ('get_query_set', 'get_queryset'),
151+ )
152+
153+
154+class ChangeList(six.with_metaclass(RenameChangeListMethods)):
155 def __init__(self, request, model, list_display, list_display_links,
156 list_filter, date_hierarchy, search_fields, list_select_related,
157 list_per_page, list_max_show_all, list_editable, model_admin):
158 self.model = model
159 self.opts = model._meta
160 self.lookup_opts = self.opts
161- self.root_query_set = model_admin.queryset(request)
162+ self.root_query_set = model_admin.get_queryset(request)
163 self.list_display = list_display
164 self.list_display_links = list_display_links
165 self.list_filter = list_filter
166@@ -70,7 +78,7 @@ class ChangeList(object):
167 else:
168 self.list_editable = list_editable
169 self.query = request.GET.get(SEARCH_VAR, '')
170- self.query_set = self.get_query_set(request)
171+ self.query_set = self.get_queryset(request)
172 self.get_results(request)
173 if self.is_popup:
174 title = ugettext('Select %s')
175@@ -304,7 +312,7 @@ class ChangeList(object):
176 ordering_fields[idx] = 'desc' if pfx == '-' else 'asc'
177 return ordering_fields
178
179- def get_query_set(self, request):
180+ def get_queryset(self, request):
181 # First, we collect all the declared list filters.
182 (self.filter_specs, self.has_filters, remaining_lookup_params,
183 use_distinct) = self.get_filters(request)
184diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py
185index 7b81667..0abc361 100644
186--- a/django/contrib/auth/admin.py
187+++ b/django/contrib/auth/admin.py
188@@ -118,7 +118,7 @@ class UserAdmin(admin.ModelAdmin):
189 def user_change_password(self, request, id, form_url=''):
190 if not self.has_change_permission(request):
191 raise PermissionDenied
192- user = get_object_or_404(self.queryset(request), pk=id)
193+ user = get_object_or_404(self.get_queryset(request), pk=id)
194 if request.method == 'POST':
195 form = self.change_password_form(user, request.POST)
196 if form.is_valid():
197diff --git a/django/contrib/comments/managers.py b/django/contrib/comments/managers.py
198index bc0fc5f..6562004 100644
199--- a/django/contrib/comments/managers.py
200+++ b/django/contrib/comments/managers.py
201@@ -8,7 +8,7 @@ class CommentManager(models.Manager):
202 """
203 QuerySet for all comments currently in the moderation queue.
204 """
205- return self.get_query_set().filter(is_public=False, is_removed=False)
206+ return self.get_queryset().filter(is_public=False, is_removed=False)
207
208 def for_model(self, model):
209 """
210@@ -16,7 +16,7 @@ class CommentManager(models.Manager):
211 a class).
212 """
213 ct = ContentType.objects.get_for_model(model)
214- qs = self.get_query_set().filter(content_type=ct)
215+ qs = self.get_queryset().filter(content_type=ct)
216 if isinstance(model, models.Model):
217 qs = qs.filter(object_pk=force_text(model._get_pk_val()))
218 return qs
219diff --git a/django/contrib/comments/templatetags/comments.py b/django/contrib/comments/templatetags/comments.py
220index 4d4eb23..8d21b7b 100644
221--- a/django/contrib/comments/templatetags/comments.py
222+++ b/django/contrib/comments/templatetags/comments.py
223@@ -3,11 +3,20 @@ from django.template.loader import render_to_string
224 from django.conf import settings
225 from django.contrib.contenttypes.models import ContentType
226 from django.contrib import comments
227+from django.utils import six
228+from django.utils.deprecation import RenameMethodsBase
229 from django.utils.encoding import smart_text
230
231 register = template.Library()
232
233-class BaseCommentNode(template.Node):
234+
235+class RenameBaseCommentNodeMethods(RenameMethodsBase):
236+ renamed_methods = (
237+ ('get_query_set', 'get_queryset'),
238+ )
239+
240+
241+class BaseCommentNode(six.with_metaclass(RenameBaseCommentNodeMethods, template.Node)):
242 """
243 Base helper class (abstract) for handling the get_comment_* template tags.
244 Looks a bit strange, but the subclasses below should make this a bit more
245@@ -64,11 +73,11 @@ class BaseCommentNode(template.Node):
246 self.comment = comment
247
248 def render(self, context):
249- qs = self.get_query_set(context)
250+ qs = self.get_queryset(context)
251 context[self.as_varname] = self.get_context_value_from_queryset(context, qs)
252 return ''
253
254- def get_query_set(self, context):
255+ def get_queryset(self, context):
256 ctype, object_pk = self.get_target_ctype_pk(context)
257 if not object_pk:
258 return self.comment_model.objects.none()
259@@ -205,7 +214,7 @@ class RenderCommentListNode(CommentListNode):
260 "comments/%s/list.html" % ctype.app_label,
261 "comments/list.html"
262 ]
263- qs = self.get_query_set(context)
264+ qs = self.get_queryset(context)
265 context.push()
266 liststr = render_to_string(template_search_list, {
267 "comment_list" : self.get_context_value_from_queryset(context, qs)
268diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py
269index 20ff704..d540cef 100644
270--- a/django/contrib/contenttypes/generic.py
271+++ b/django/contrib/contenttypes/generic.py
272@@ -16,10 +16,18 @@ from django.forms import ModelForm
273 from django.forms.models import BaseModelFormSet, modelformset_factory, save_instance
274 from django.contrib.admin.options import InlineModelAdmin, flatten_fieldsets
275 from django.contrib.contenttypes.models import ContentType
276+from django.utils import six
277+from django.utils.deprecation import RenameMethodsBase
278 from django.utils.encoding import smart_text
279
280
281-class GenericForeignKey(object):
282+class RenameGenericForeignKeyMethods(RenameMethodsBase):
283+ renamed_methods = (
284+ ('get_prefetch_query_set', 'get_prefetch_queryset'),
285+ )
286+
287+
288+class GenericForeignKey(six.with_metaclass(RenameGenericForeignKeyMethods)):
289 """
290 Provides a generic relation to any object through content-type/object-id
291 fields.
292@@ -60,7 +68,7 @@ class GenericForeignKey(object):
293 # This should never happen. I love comments like this, don't you?
294 raise Exception("Impossible arguments to GFK.get_content_type!")
295
296- def get_prefetch_query_set(self, instances):
297+ def get_prefetch_queryset(self, instances):
298 # For efficiency, group the instances by content type and then do one
299 # query per model
300 fk_dict = defaultdict(set)
301@@ -316,21 +324,21 @@ def create_generic_related_manager(superclass):
302 '%s__exact' % object_id_field_name: instance._get_pk_val(),
303 }
304
305- def get_query_set(self):
306+ def get_queryset(self):
307 try:
308 return self.instance._prefetched_objects_cache[self.prefetch_cache_name]
309 except (AttributeError, KeyError):
310 db = self._db or router.db_for_read(self.model, instance=self.instance)
311- return super(GenericRelatedObjectManager, self).get_query_set().using(db).filter(**self.core_filters)
312+ return super(GenericRelatedObjectManager, self).get_queryset().using(db).filter(**self.core_filters)
313
314- def get_prefetch_query_set(self, instances):
315+ def get_prefetch_queryset(self, instances):
316 db = self._db or router.db_for_read(self.model, instance=instances[0])
317 query = {
318 '%s__pk' % self.content_type_field_name: self.content_type.id,
319 '%s__in' % self.object_id_field_name:
320 set(obj._get_pk_val() for obj in instances)
321 }
322- qs = super(GenericRelatedObjectManager, self).get_query_set().using(db).filter(**query)
323+ qs = super(GenericRelatedObjectManager, self).get_queryset().using(db).filter(**query)
324 # We (possibly) need to convert object IDs to the type of the
325 # instances' PK in order to match up instances:
326 object_id_converter = instances[0]._meta.pk.to_python
327diff --git a/django/contrib/gis/db/models/manager.py b/django/contrib/gis/db/models/manager.py
328index 61fb821..aa57e3a 100644
329--- a/django/contrib/gis/db/models/manager.py
330+++ b/django/contrib/gis/db/models/manager.py
331@@ -9,95 +9,95 @@ class GeoManager(Manager):
332 # properly.
333 use_for_related_fields = True
334
335- def get_query_set(self):
336+ def get_queryset(self):
337 return GeoQuerySet(self.model, using=self._db)
338
339 def area(self, *args, **kwargs):
340- return self.get_query_set().area(*args, **kwargs)
341+ return self.get_queryset().area(*args, **kwargs)
342
343 def centroid(self, *args, **kwargs):
344- return self.get_query_set().centroid(*args, **kwargs)
345+ return self.get_queryset().centroid(*args, **kwargs)
346
347 def collect(self, *args, **kwargs):
348- return self.get_query_set().collect(*args, **kwargs)
349+ return self.get_queryset().collect(*args, **kwargs)
350
351 def difference(self, *args, **kwargs):
352- return self.get_query_set().difference(*args, **kwargs)
353+ return self.get_queryset().difference(*args, **kwargs)
354
355 def distance(self, *args, **kwargs):
356- return self.get_query_set().distance(*args, **kwargs)
357+ return self.get_queryset().distance(*args, **kwargs)
358
359 def envelope(self, *args, **kwargs):
360- return self.get_query_set().envelope(*args, **kwargs)
361+ return self.get_queryset().envelope(*args, **kwargs)
362
363 def extent(self, *args, **kwargs):
364- return self.get_query_set().extent(*args, **kwargs)
365+ return self.get_queryset().extent(*args, **kwargs)
366
367 def extent3d(self, *args, **kwargs):
368- return self.get_query_set().extent3d(*args, **kwargs)
369+ return self.get_queryset().extent3d(*args, **kwargs)
370
371 def force_rhr(self, *args, **kwargs):
372- return self.get_query_set().force_rhr(*args, **kwargs)
373+ return self.get_queryset().force_rhr(*args, **kwargs)
374
375 def geohash(self, *args, **kwargs):
376- return self.get_query_set().geohash(*args, **kwargs)
377+ return self.get_queryset().geohash(*args, **kwargs)
378
379 def geojson(self, *args, **kwargs):
380- return self.get_query_set().geojson(*args, **kwargs)
381+ return self.get_queryset().geojson(*args, **kwargs)
382
383 def gml(self, *args, **kwargs):
384- return self.get_query_set().gml(*args, **kwargs)
385+ return self.get_queryset().gml(*args, **kwargs)
386
387 def intersection(self, *args, **kwargs):
388- return self.get_query_set().intersection(*args, **kwargs)
389+ return self.get_queryset().intersection(*args, **kwargs)
390
391 def kml(self, *args, **kwargs):
392- return self.get_query_set().kml(*args, **kwargs)
393+ return self.get_queryset().kml(*args, **kwargs)
394
395 def length(self, *args, **kwargs):
396- return self.get_query_set().length(*args, **kwargs)
397+ return self.get_queryset().length(*args, **kwargs)
398
399 def make_line(self, *args, **kwargs):
400- return self.get_query_set().make_line(*args, **kwargs)
401+ return self.get_queryset().make_line(*args, **kwargs)
402
403 def mem_size(self, *args, **kwargs):
404- return self.get_query_set().mem_size(*args, **kwargs)
405+ return self.get_queryset().mem_size(*args, **kwargs)
406
407 def num_geom(self, *args, **kwargs):
408- return self.get_query_set().num_geom(*args, **kwargs)
409+ return self.get_queryset().num_geom(*args, **kwargs)
410
411 def num_points(self, *args, **kwargs):
412- return self.get_query_set().num_points(*args, **kwargs)
413+ return self.get_queryset().num_points(*args, **kwargs)
414
415 def perimeter(self, *args, **kwargs):
416- return self.get_query_set().perimeter(*args, **kwargs)
417+ return self.get_queryset().perimeter(*args, **kwargs)
418
419 def point_on_surface(self, *args, **kwargs):
420- return self.get_query_set().point_on_surface(*args, **kwargs)
421+ return self.get_queryset().point_on_surface(*args, **kwargs)
422
423 def reverse_geom(self, *args, **kwargs):
424- return self.get_query_set().reverse_geom(*args, **kwargs)
425+ return self.get_queryset().reverse_geom(*args, **kwargs)
426
427 def scale(self, *args, **kwargs):
428- return self.get_query_set().scale(*args, **kwargs)
429+ return self.get_queryset().scale(*args, **kwargs)
430
431 def snap_to_grid(self, *args, **kwargs):
432- return self.get_query_set().snap_to_grid(*args, **kwargs)
433+ return self.get_queryset().snap_to_grid(*args, **kwargs)
434
435 def svg(self, *args, **kwargs):
436- return self.get_query_set().svg(*args, **kwargs)
437+ return self.get_queryset().svg(*args, **kwargs)
438
439 def sym_difference(self, *args, **kwargs):
440- return self.get_query_set().sym_difference(*args, **kwargs)
441+ return self.get_queryset().sym_difference(*args, **kwargs)
442
443 def transform(self, *args, **kwargs):
444- return self.get_query_set().transform(*args, **kwargs)
445+ return self.get_queryset().transform(*args, **kwargs)
446
447 def translate(self, *args, **kwargs):
448- return self.get_query_set().translate(*args, **kwargs)
449+ return self.get_queryset().translate(*args, **kwargs)
450
451 def union(self, *args, **kwargs):
452- return self.get_query_set().union(*args, **kwargs)
453+ return self.get_queryset().union(*args, **kwargs)
454
455 def unionagg(self, *args, **kwargs):
456- return self.get_query_set().unionagg(*args, **kwargs)
457+ return self.get_queryset().unionagg(*args, **kwargs)
458diff --git a/django/contrib/sites/managers.py b/django/contrib/sites/managers.py
459index 3df485a..becb35b 100644
460--- a/django/contrib/sites/managers.py
461+++ b/django/contrib/sites/managers.py
462@@ -35,7 +35,7 @@ class CurrentSiteManager(models.Manager):
463 (self.__class__.__name__, self.__field_name, self.model._meta.object_name))
464 self.__is_validated = True
465
466- def get_query_set(self):
467+ def get_queryset(self):
468 if not self.__is_validated:
469 self._validate_field_name()
470- return super(CurrentSiteManager, self).get_query_set().filter(**{self.__field_name + '__id__exact': settings.SITE_ID})
471+ return super(CurrentSiteManager, self).get_queryset().filter(**{self.__field_name + '__id__exact': settings.SITE_ID})
472diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
473index 01b8a55..843b78e 100644
474--- a/django/db/models/fields/related.py
475+++ b/django/db/models/fields/related.py
476@@ -11,6 +11,7 @@ from django.db.models.query_utils import QueryWrapper
477 from django.db.models.deletion import CASCADE
478 from django.utils.encoding import smart_text
479 from django.utils import six
480+from django.utils.deprecation import RenameMethodsBase
481 from django.utils.translation import ugettext_lazy as _, string_concat
482 from django.utils.functional import curry, cached_property
483 from django.core import exceptions
484@@ -225,7 +226,14 @@ class RelatedField(object):
485 return self.rel.related_name or self.opts.model_name
486
487
488-class SingleRelatedObjectDescriptor(object):
489+class RenameRelatedObjectDescriptorMethods(RenameMethodsBase):
490+ renamed_methods = (
491+ ('get_query_set', 'get_queryset'),
492+ ('get_prefetch_query_set', 'get_prefetch_queryset'),
493+ )
494+
495+
496+class SingleRelatedObjectDescriptor(six.with_metaclass(RenameRelatedObjectDescriptorMethods)):
497 # This class provides the functionality that makes the related-object
498 # managers available as attributes on a model class, for fields that have
499 # a single "remote" value, on the class pointed to by a related field.
500@@ -238,16 +246,16 @@ class SingleRelatedObjectDescriptor(object):
501 def is_cached(self, instance):
502 return hasattr(instance, self.cache_name)
503
504- def get_query_set(self, **db_hints):
505+ def get_queryset(self, **db_hints):
506 db = router.db_for_read(self.related.model, **db_hints)
507 return self.related.model._base_manager.using(db)
508
509- def get_prefetch_query_set(self, instances):
510+ def get_prefetch_queryset(self, instances):
511 rel_obj_attr = attrgetter(self.related.field.attname)
512 instance_attr = lambda obj: obj._get_pk_val()
513 instances_dict = dict((instance_attr(inst), inst) for inst in instances)
514 params = {'%s__pk__in' % self.related.field.name: list(instances_dict)}
515- qs = self.get_query_set(instance=instances[0]).filter(**params)
516+ qs = self.get_queryset(instance=instances[0]).filter(**params)
517 # Since we're going to assign directly in the cache,
518 # we must manage the reverse relation cache manually.
519 rel_obj_cache_name = self.related.field.get_cache_name()
520@@ -268,7 +276,7 @@ class SingleRelatedObjectDescriptor(object):
521 else:
522 params = {'%s__pk' % self.related.field.name: related_pk}
523 try:
524- rel_obj = self.get_query_set(instance=instance).get(**params)
525+ rel_obj = self.get_queryset(instance=instance).get(**params)
526 except self.related.model.DoesNotExist:
527 rel_obj = None
528 else:
529@@ -321,7 +329,7 @@ class SingleRelatedObjectDescriptor(object):
530 setattr(value, self.related.field.get_cache_name(), instance)
531
532
533-class ReverseSingleRelatedObjectDescriptor(object):
534+class ReverseSingleRelatedObjectDescriptor(six.with_metaclass(RenameRelatedObjectDescriptorMethods)):
535 # This class provides the functionality that makes the related-object
536 # managers available as attributes on a model class, for fields that have
537 # a single "remote" value, on the class that defines the related field.
538@@ -334,7 +342,7 @@ class ReverseSingleRelatedObjectDescriptor(object):
539 def is_cached(self, instance):
540 return hasattr(instance, self.cache_name)
541
542- def get_query_set(self, **db_hints):
543+ def get_queryset(self, **db_hints):
544 db = router.db_for_read(self.field.rel.to, **db_hints)
545 rel_mgr = self.field.rel.to._default_manager
546 # If the related manager indicates that it should be used for
547@@ -344,7 +352,7 @@ class ReverseSingleRelatedObjectDescriptor(object):
548 else:
549 return QuerySet(self.field.rel.to).using(db)
550
551- def get_prefetch_query_set(self, instances):
552+ def get_prefetch_queryset(self, instances):
553 other_field = self.field.rel.get_related_field()
554 rel_obj_attr = attrgetter(other_field.attname)
555 instance_attr = attrgetter(self.field.attname)
556@@ -353,7 +361,7 @@ class ReverseSingleRelatedObjectDescriptor(object):
557 params = {'%s__pk__in' % self.field.rel.field_name: list(instances_dict)}
558 else:
559 params = {'%s__in' % self.field.rel.field_name: list(instances_dict)}
560- qs = self.get_query_set(instance=instances[0]).filter(**params)
561+ qs = self.get_queryset(instance=instances[0]).filter(**params)
562 # Since we're going to assign directly in the cache,
563 # we must manage the reverse relation cache manually.
564 if not self.field.rel.multiple:
565@@ -378,7 +386,7 @@ class ReverseSingleRelatedObjectDescriptor(object):
566 params = {'%s__%s' % (self.field.rel.field_name, other_field.rel.field_name): val}
567 else:
568 params = {'%s__exact' % self.field.rel.field_name: val}
569- qs = self.get_query_set(instance=instance)
570+ qs = self.get_queryset(instance=instance)
571 # Assuming the database enforces foreign keys, this won't fail.
572 rel_obj = qs.get(**params)
573 if not self.field.rel.multiple:
574@@ -490,26 +498,26 @@ class ForeignRelatedObjectsDescriptor(object):
575 }
576 self.model = rel_model
577
578- def get_query_set(self):
579+ def get_queryset(self):
580 try:
581 return self.instance._prefetched_objects_cache[rel_field.related_query_name()]
582 except (AttributeError, KeyError):
583 db = self._db or router.db_for_read(self.model, instance=self.instance)
584- qs = super(RelatedManager, self).get_query_set().using(db).filter(**self.core_filters)
585+ qs = super(RelatedManager, self).get_queryset().using(db).filter(**self.core_filters)
586 val = getattr(self.instance, attname)
587 if val is None or val == '' and connections[db].features.interprets_empty_strings_as_nulls:
588 return qs.none()
589 qs._known_related_objects = {rel_field: {self.instance.pk: self.instance}}
590 return qs
591
592- def get_prefetch_query_set(self, instances):
593+ def get_prefetch_queryset(self, instances):
594 rel_obj_attr = attrgetter(rel_field.attname)
595 instance_attr = attrgetter(attname)
596 instances_dict = dict((instance_attr(inst), inst) for inst in instances)
597 db = self._db or router.db_for_read(self.model, instance=instances[0])
598 query = {'%s__%s__in' % (rel_field.name, attname): list(instances_dict)}
599- qs = super(RelatedManager, self).get_query_set().using(db).filter(**query)
600- # Since we just bypassed this class' get_query_set(), we must manage
601+ qs = super(RelatedManager, self).get_queryset().using(db).filter(**query)
602+ # Since we just bypassed this class' get_queryset(), we must manage
603 # the reverse relation manually.
604 for rel_obj in qs:
605 instance = instances_dict[rel_obj_attr(rel_obj)]
606@@ -603,20 +611,20 @@ def create_many_related_manager(superclass, rel):
607 else:
608 return obj.pk
609
610- def get_query_set(self):
611+ def get_queryset(self):
612 try:
613 return self.instance._prefetched_objects_cache[self.prefetch_cache_name]
614 except (AttributeError, KeyError):
615 db = self._db or router.db_for_read(self.instance.__class__, instance=self.instance)
616- return super(ManyRelatedManager, self).get_query_set().using(db)._next_is_sticky().filter(**self.core_filters)
617+ return super(ManyRelatedManager, self).get_queryset().using(db)._next_is_sticky().filter(**self.core_filters)
618
619- def get_prefetch_query_set(self, instances):
620+ def get_prefetch_queryset(self, instances):
621 instance = instances[0]
622 from django.db import connections
623 db = self._db or router.db_for_read(instance.__class__, instance=instance)
624 query = {'%s__pk__in' % self.query_field_name:
625 set(obj._get_pk_val() for obj in instances)}
626- qs = super(ManyRelatedManager, self).get_query_set().using(db)._next_is_sticky().filter(**query)
627+ qs = super(ManyRelatedManager, self).get_queryset().using(db)._next_is_sticky().filter(**query)
628
629 # M2M: need to annotate the query in order to get the primary model
630 # that the secondary model was actually related to. We know that
631diff --git a/django/db/models/manager.py b/django/db/models/manager.py
632index b1f2e10..687c5ab 100644
633--- a/django/db/models/manager.py
634+++ b/django/db/models/manager.py
635@@ -3,7 +3,8 @@ from django.db import router
636 from django.db.models.query import QuerySet, insert_query, RawQuerySet
637 from django.db.models import signals
638 from django.db.models.fields import FieldDoesNotExist
639-
640+from django.utils import six
641+from django.utils.deprecation import RenameMethodsBase
642
643 def ensure_default_manager(sender, **kwargs):
644 """
645@@ -47,7 +48,15 @@ def ensure_default_manager(sender, **kwargs):
646 signals.class_prepared.connect(ensure_default_manager)
647
648
649-class Manager(object):
650+class RenameManagerMethods(RenameMethodsBase):
651+ renamed_methods = (
652+ ('get_query_set', 'get_queryset'),
653+ ('get_prefetch_query_set', 'get_prefetch_queryset'),
654+ )
655+
656+
657+class Manager(six.with_metaclass(RenameManagerMethods)):
658+# class Manager(object):
659 # Tracks each time a Manager instance is created. Used to retain order.
660 creation_counter = 0
661
662@@ -112,113 +121,113 @@ class Manager(object):
663 # PROXIES TO QUERYSET #
664 #######################
665
666- def get_query_set(self):
667+ def get_queryset(self):
668 """Returns a new QuerySet object. Subclasses can override this method
669 to easily customize the behavior of the Manager.
670 """
671 return QuerySet(self.model, using=self._db)
672
673 def none(self):
674- return self.get_query_set().none()
675+ return self.get_queryset().none()
676
677 def all(self):
678- return self.get_query_set()
679+ return self.get_queryset()
680
681 def count(self):
682- return self.get_query_set().count()
683+ return self.get_queryset().count()
684
685 def dates(self, *args, **kwargs):
686- return self.get_query_set().dates(*args, **kwargs)
687+ return self.get_queryset().dates(*args, **kwargs)
688
689 def datetimes(self, *args, **kwargs):
690- return self.get_query_set().datetimes(*args, **kwargs)
691+ return self.get_queryset().datetimes(*args, **kwargs)
692
693 def distinct(self, *args, **kwargs):
694- return self.get_query_set().distinct(*args, **kwargs)
695+ return self.get_queryset().distinct(*args, **kwargs)
696
697 def extra(self, *args, **kwargs):
698- return self.get_query_set().extra(*args, **kwargs)
699+ return self.get_queryset().extra(*args, **kwargs)
700
701 def get(self, *args, **kwargs):
702- return self.get_query_set().get(*args, **kwargs)
703+ return self.get_queryset().get(*args, **kwargs)
704
705 def get_or_create(self, **kwargs):
706- return self.get_query_set().get_or_create(**kwargs)
707+ return self.get_queryset().get_or_create(**kwargs)
708
709 def create(self, **kwargs):
710- return self.get_query_set().create(**kwargs)
711+ return self.get_queryset().create(**kwargs)
712
713 def bulk_create(self, *args, **kwargs):
714- return self.get_query_set().bulk_create(*args, **kwargs)
715+ return self.get_queryset().bulk_create(*args, **kwargs)
716
717 def filter(self, *args, **kwargs):
718- return self.get_query_set().filter(*args, **kwargs)
719+ return self.get_queryset().filter(*args, **kwargs)
720
721 def aggregate(self, *args, **kwargs):
722- return self.get_query_set().aggregate(*args, **kwargs)
723+ return self.get_queryset().aggregate(*args, **kwargs)
724
725 def annotate(self, *args, **kwargs):
726- return self.get_query_set().annotate(*args, **kwargs)
727+ return self.get_queryset().annotate(*args, **kwargs)
728
729 def complex_filter(self, *args, **kwargs):
730- return self.get_query_set().complex_filter(*args, **kwargs)
731+ return self.get_queryset().complex_filter(*args, **kwargs)
732
733 def exclude(self, *args, **kwargs):
734- return self.get_query_set().exclude(*args, **kwargs)
735+ return self.get_queryset().exclude(*args, **kwargs)
736
737 def in_bulk(self, *args, **kwargs):
738- return self.get_query_set().in_bulk(*args, **kwargs)
739+ return self.get_queryset().in_bulk(*args, **kwargs)
740
741 def iterator(self, *args, **kwargs):
742- return self.get_query_set().iterator(*args, **kwargs)
743+ return self.get_queryset().iterator(*args, **kwargs)
744
745 def earliest(self, *args, **kwargs):
746- return self.get_query_set().earliest(*args, **kwargs)
747+ return self.get_queryset().earliest(*args, **kwargs)
748
749 def latest(self, *args, **kwargs):
750- return self.get_query_set().latest(*args, **kwargs)
751+ return self.get_queryset().latest(*args, **kwargs)
752
753 def order_by(self, *args, **kwargs):
754- return self.get_query_set().order_by(*args, **kwargs)
755+ return self.get_queryset().order_by(*args, **kwargs)
756
757 def select_for_update(self, *args, **kwargs):
758- return self.get_query_set().select_for_update(*args, **kwargs)
759+ return self.get_queryset().select_for_update(*args, **kwargs)
760
761 def select_related(self, *args, **kwargs):
762- return self.get_query_set().select_related(*args, **kwargs)
763+ return self.get_queryset().select_related(*args, **kwargs)
764
765 def prefetch_related(self, *args, **kwargs):
766- return self.get_query_set().prefetch_related(*args, **kwargs)
767+ return self.get_queryset().prefetch_related(*args, **kwargs)
768
769 def values(self, *args, **kwargs):
770- return self.get_query_set().values(*args, **kwargs)
771+ return self.get_queryset().values(*args, **kwargs)
772
773 def values_list(self, *args, **kwargs):
774- return self.get_query_set().values_list(*args, **kwargs)
775+ return self.get_queryset().values_list(*args, **kwargs)
776
777 def update(self, *args, **kwargs):
778- return self.get_query_set().update(*args, **kwargs)
779+ return self.get_queryset().update(*args, **kwargs)
780
781 def reverse(self, *args, **kwargs):
782- return self.get_query_set().reverse(*args, **kwargs)
783+ return self.get_queryset().reverse(*args, **kwargs)
784
785 def defer(self, *args, **kwargs):
786- return self.get_query_set().defer(*args, **kwargs)
787+ return self.get_queryset().defer(*args, **kwargs)
788
789 def only(self, *args, **kwargs):
790- return self.get_query_set().only(*args, **kwargs)
791+ return self.get_queryset().only(*args, **kwargs)
792
793 def using(self, *args, **kwargs):
794- return self.get_query_set().using(*args, **kwargs)
795+ return self.get_queryset().using(*args, **kwargs)
796
797 def exists(self, *args, **kwargs):
798- return self.get_query_set().exists(*args, **kwargs)
799+ return self.get_queryset().exists(*args, **kwargs)
800
801 def _insert(self, objs, fields, **kwargs):
802 return insert_query(self.model, objs, fields, **kwargs)
803
804 def _update(self, values, **kwargs):
805- return self.get_query_set()._update(values, **kwargs)
806+ return self.get_queryset()._update(values, **kwargs)
807
808 def raw(self, raw_query, params=None, *args, **kwargs):
809 return RawQuerySet(raw_query=raw_query, model=self.model, params=params, using=self._db, *args, **kwargs)
810@@ -265,5 +274,5 @@ class EmptyManager(Manager):
811 super(EmptyManager, self).__init__()
812 self.model = model
813
814- def get_query_set(self):
815- return super(EmptyManager, self).get_query_set().none()
816+ def get_queryset(self):
817+ return super(EmptyManager, self).get_queryset().none()
818diff --git a/django/db/models/query.py b/django/db/models/query.py
819index ec35f8a..30be30c 100644
820--- a/django/db/models/query.py
821+++ b/django/db/models/query.py
822@@ -1733,9 +1733,9 @@ def prefetch_related_objects(result_cache, related_lookups):
823 def get_prefetcher(instance, attr):
824 """
825 For the attribute 'attr' on the given instance, finds
826- an object that has a get_prefetch_query_set().
827+ an object that has a get_prefetch_queryset().
828 Returns a 4 tuple containing:
829- (the object with get_prefetch_query_set (or None),
830+ (the object with get_prefetch_queryset (or None),
831 the descriptor object representing this relationship (or None),
832 a boolean that is False if the attribute was not found at all,
833 a boolean that is True if the attribute has already been fetched)
834@@ -1758,8 +1758,8 @@ def get_prefetcher(instance, attr):
835 attr_found = True
836 if rel_obj_descriptor:
837 # singly related object, descriptor object has the
838- # get_prefetch_query_set() method.
839- if hasattr(rel_obj_descriptor, 'get_prefetch_query_set'):
840+ # get_prefetch_queryset() method.
841+ if hasattr(rel_obj_descriptor, 'get_prefetch_queryset'):
842 prefetcher = rel_obj_descriptor
843 if rel_obj_descriptor.is_cached(instance):
844 is_fetched = True
845@@ -1768,7 +1768,7 @@ def get_prefetcher(instance, attr):
846 # the attribute on the instance rather than the class to
847 # support many related managers
848 rel_obj = getattr(instance, attr)
849- if hasattr(rel_obj, 'get_prefetch_query_set'):
850+ if hasattr(rel_obj, 'get_prefetch_queryset'):
851 prefetcher = rel_obj
852 return prefetcher, rel_obj_descriptor, attr_found, is_fetched
853
854@@ -1784,7 +1784,7 @@ def prefetch_one_level(instances, prefetcher, attname):
855 prefetches that must be done due to prefetch_related lookups
856 found from default managers.
857 """
858- # prefetcher must have a method get_prefetch_query_set() which takes a list
859+ # prefetcher must have a method get_prefetch_queryset() which takes a list
860 # of instances, and returns a tuple:
861
862 # (queryset of instances of self.model that are related to passed in instances,
863@@ -1797,7 +1797,7 @@ def prefetch_one_level(instances, prefetcher, attname):
864 # in a dictionary.
865
866 rel_qs, rel_obj_attr, instance_attr, single, cache_name =\
867- prefetcher.get_prefetch_query_set(instances)
868+ prefetcher.get_prefetch_queryset(instances)
869 # We have to handle the possibility that the default manager itself added
870 # prefetch_related lookups to the QuerySet we just got back. We don't want to
871 # trigger the prefetch_related functionality by evaluating the query.
872diff --git a/django/forms/models.py b/django/forms/models.py
873index 3905e9e..b44f811 100644
874--- a/django/forms/models.py
875+++ b/django/forms/models.py
876@@ -479,7 +479,7 @@ class BaseModelFormSet(BaseFormSet):
877 if self.queryset is not None:
878 qs = self.queryset
879 else:
880- qs = self.model._default_manager.get_query_set()
881+ qs = self.model._default_manager.get_queryset()
882
883 # If the queryset isn't already ordered we need to add an
884 # artificial ordering here to make sure that all formsets
885@@ -669,9 +669,9 @@ class BaseModelFormSet(BaseFormSet):
886 except IndexError:
887 pk_value = None
888 if isinstance(pk, OneToOneField) or isinstance(pk, ForeignKey):
889- qs = pk.rel.to._default_manager.get_query_set()
890+ qs = pk.rel.to._default_manager.get_queryset()
891 else:
892- qs = self.model._default_manager.get_query_set()
893+ qs = self.model._default_manager.get_queryset()
894 qs = qs.using(form.instance._state.db)
895 if form._meta.widgets:
896 widget = form._meta.widgets.get(self._pk_field.name, HiddenInput)
897diff --git a/django/utils/deprecation.py b/django/utils/deprecation.py
898new file mode 100644
899index 0000000..fb3d2c3
900--- /dev/null
901+++ b/django/utils/deprecation.py
902@@ -0,0 +1,59 @@
903+import inspect
904+import warnings
905+
906+
907+class warn_about_renamed_method(object):
908+ def __init__(self, class_name, old_method_name, new_method_name):
909+ self.class_name = class_name
910+ self.old_method_name = old_method_name
911+ self.new_method_name = new_method_name
912+
913+ def __call__(self, f):
914+ def wrapped(*args, **kwargs):
915+ warnings.warn(
916+ "`%s.%s` is deprecated, use `%s` instead." %
917+ (self.class_name, self.old_method_name, self.new_method_name),
918+ PendingDeprecationWarning, 2)
919+ return f(*args, **kwargs)
920+ return wrapped
921+
922+
923+class RenameMethodsBase(type):
924+ """
925+ Handles the deprecation paths when renaming a method.
926+
927+ It does the following:
928+ 1) Define the new method if missing and complain about it.
929+ 2) Define the old method if missing.
930+ 3) Complain whenever an old method is called.
931+
932+ See #15363 for more details.
933+ """
934+
935+ renamed_methods = ()
936+
937+ def __new__(cls, name, bases, attrs):
938+ new_class = super(RenameMethodsBase, cls).__new__(cls, name, bases, attrs)
939+
940+ for base in inspect.getmro(new_class):
941+ for old_method_name, new_method_name in cls.renamed_methods:
942+ old_method = base.__dict__.get(old_method_name)
943+ new_method = base.__dict__.get(new_method_name)
944+
945+ info = (base.__name__, old_method_name, new_method_name)
946+
947+ # Define the new method if missing and complain about it
948+ if not new_method and old_method:
949+ warnings.warn(
950+ "`%s.%s` method should be renamed `%s`." % info,
951+ PendingDeprecationWarning, 2)
952+ wrapped_old_method = warn_about_renamed_method(*info)(old_method)
953+ setattr(base, new_method_name, wrapped_old_method)
954+ setattr(base, old_method_name, wrapped_old_method)
955+
956+ # Define the old method as a wrapped call to the new method.
957+ if not old_method and new_method:
958+ wrapped_new_method = warn_about_renamed_method(*info)(new_method)
959+ setattr(base, old_method_name, wrapped_new_method)
960+
961+ return new_class
962diff --git a/docs/faq/admin.txt b/docs/faq/admin.txt
963index 30d452c..1d9a7c7 100644
964--- a/docs/faq/admin.txt
965+++ b/docs/faq/admin.txt
966@@ -49,7 +49,7 @@ How do I limit admin access so that objects can only be edited by the users who
967 The :class:`~django.contrib.admin.ModelAdmin` class also provides customization
968 hooks that allow you to control the visibility and editability of objects in the
969 admin. Using the same trick of extracting the user from the request, the
970-:meth:`~django.contrib.admin.ModelAdmin.queryset` and
971+:meth:`~django.contrib.admin.ModelAdmin.get_queryset` and
972 :meth:`~django.contrib.admin.ModelAdmin.has_change_permission` can be used to
973 control the visibility and editability of objects in the admin.
974
975diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
976index 9ab1984..827518d 100644
977--- a/docs/ref/contrib/admin/index.txt
978+++ b/docs/ref/contrib/admin/index.txt
979@@ -696,7 +696,7 @@ subclass::
980 Only show the lookups if there actually is
981 anyone born in the corresponding decades.
982 """
983- qs = model_admin.queryset(request)
984+ qs = model_admin.get_queryset(request)
985 if qs.filter(birthday__gte=date(1980, 1, 1),
986 birthday__lte=date(1989, 12, 31)).exists():
987 yield ('80s', _('in the eighties'))
988@@ -1319,16 +1319,16 @@ templates used by the :class:`ModelAdmin` views:
989 be interpreted as meaning that the current user is not permitted to delete
990 any object of this type).
991
992-.. method:: ModelAdmin.queryset(self, request)
993+.. method:: ModelAdmin.get_queryset(self, request)
994
995- The ``queryset`` method on a ``ModelAdmin`` returns a
996+ The ``get_queryset`` method on a ``ModelAdmin`` returns a
997 :class:`~django.db.models.query.QuerySet` of all model instances that
998 can be edited by the admin site. One use case for overriding this method
999 is to show objects owned by the logged-in user::
1000
1001 class MyModelAdmin(admin.ModelAdmin):
1002- def queryset(self, request):
1003- qs = super(MyModelAdmin, self).queryset(request)
1004+ def get_queryset(self, request):
1005+ qs = super(MyModelAdmin, self).get_queryset(request)
1006 if request.user.is_superuser:
1007 return qs
1008 return qs.filter(author=request.user)
1009@@ -1542,7 +1542,7 @@ adds some of its own (the shared features are actually defined in the
1010 - :attr:`~ModelAdmin.filter_vertical`
1011 - :attr:`~ModelAdmin.ordering`
1012 - :attr:`~ModelAdmin.prepopulated_fields`
1013-- :meth:`~ModelAdmin.queryset`
1014+- :meth:`~ModelAdmin.get_queryset`
1015 - :attr:`~ModelAdmin.radio_fields`
1016 - :attr:`~ModelAdmin.readonly_fields`
1017 - :attr:`~InlineModelAdmin.raw_id_fields`
1018diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
1019index f77f87d..638deef 100644
1020--- a/docs/ref/models/querysets.txt
1021+++ b/docs/ref/models/querysets.txt
1022@@ -1591,32 +1591,32 @@ The most efficient method of finding whether a model with a unique field
1023 (e.g. ``primary_key``) is a member of a :class:`.QuerySet` is::
1024
1025 entry = Entry.objects.get(pk=123)
1026- if some_query_set.filter(pk=entry.pk).exists():
1027+ if some_queryset.filter(pk=entry.pk).exists():
1028 print("Entry contained in queryset")
1029
1030 Which will be faster than the following which requires evaluating and iterating
1031 through the entire queryset::
1032
1033- if entry in some_query_set:
1034+ if entry in some_queryset:
1035 print("Entry contained in QuerySet")
1036
1037 And to find whether a queryset contains any items::
1038
1039- if some_query_set.exists():
1040- print("There is at least one object in some_query_set")
1041+ if some_queryset.exists():
1042+ print("There is at least one object in some_queryset")
1043
1044 Which will be faster than::
1045
1046- if some_query_set:
1047- print("There is at least one object in some_query_set")
1048+ if some_queryset:
1049+ print("There is at least one object in some_queryset")
1050
1051 ... but not by a large degree (hence needing a large queryset for efficiency
1052 gains).
1053
1054-Additionally, if a ``some_query_set`` has not yet been evaluated, but you know
1055-that it will be at some point, then using ``some_query_set.exists()`` will do
1056+Additionally, if a ``some_queryset`` has not yet been evaluated, but you know
1057+that it will be at some point, then using ``some_queryset.exists()`` will do
1058 more overall work (one query for the existence check plus an extra one to later
1059-retrieve the results) than simply using ``bool(some_query_set)``, which
1060+retrieve the results) than simply using ``bool(some_queryset)``, which
1061 retrieves the results and then checks if any were returned.
1062
1063 update
1064diff --git a/docs/topics/db/managers.txt b/docs/topics/db/managers.txt
1065index a14616a..a90085f 100644
1066--- a/docs/topics/db/managers.txt
1067+++ b/docs/topics/db/managers.txt
1068@@ -108,7 +108,7 @@ example, using this model::
1069 ...the statement ``Book.objects.all()`` will return all books in the database.
1070
1071 You can override a ``Manager``\'s base ``QuerySet`` by overriding the
1072-``Manager.get_query_set()`` method. ``get_query_set()`` should return a
1073+``Manager.get_queryset()`` method. ``get_queryset()`` should return a
1074 ``QuerySet`` with the properties you require.
1075
1076 For example, the following model has *two* ``Manager``\s -- one that returns
1077@@ -116,8 +116,8 @@ all objects, and one that returns only the books by Roald Dahl::
1078
1079 # First, define the Manager subclass.
1080 class DahlBookManager(models.Manager):
1081- def get_query_set(self):
1082- return super(DahlBookManager, self).get_query_set().filter(author='Roald Dahl')
1083+ def get_queryset(self):
1084+ return super(DahlBookManager, self).get_queryset().filter(author='Roald Dahl')
1085
1086 # Then hook it into the Book model explicitly.
1087 class Book(models.Model):
1088@@ -131,7 +131,7 @@ With this sample model, ``Book.objects.all()`` will return all books in the
1089 database, but ``Book.dahl_objects.all()`` will only return the ones written by
1090 Roald Dahl.
1091
1092-Of course, because ``get_query_set()`` returns a ``QuerySet`` object, you can
1093+Of course, because ``get_queryset()`` returns a ``QuerySet`` object, you can
1094 use ``filter()``, ``exclude()`` and all the other ``QuerySet`` methods on it.
1095 So these statements are all legal::
1096
1097@@ -147,12 +147,12 @@ models.
1098 For example::
1099
1100 class MaleManager(models.Manager):
1101- def get_query_set(self):
1102- return super(MaleManager, self).get_query_set().filter(sex='M')
1103+ def get_queryset(self):
1104+ return super(MaleManager, self).get_queryset().filter(sex='M')
1105
1106 class FemaleManager(models.Manager):
1107- def get_query_set(self):
1108- return super(FemaleManager, self).get_query_set().filter(sex='F')
1109+ def get_queryset(self):
1110+ return super(FemaleManager, self).get_queryset().filter(sex='F')
1111
1112 class Person(models.Model):
1113 first_name = models.CharField(max_length=50)
1114@@ -172,7 +172,7 @@ the "default" ``Manager``, and several parts of Django
1115 (including :djadmin:`dumpdata`) will use that ``Manager``
1116 exclusively for that model. As a result, it's a good idea to be careful in
1117 your choice of default manager in order to avoid a situation where overriding
1118-``get_query_set()`` results in an inability to retrieve objects you'd like to
1119+``get_queryset()`` results in an inability to retrieve objects you'd like to
1120 work with.
1121
1122 .. _managers-for-related-objects:
1123@@ -379,9 +379,9 @@ to from some other model. In those situations, Django has to be able to see
1124 all the objects for the model it is fetching, so that *anything* which is
1125 referred to can be retrieved.
1126
1127-If you override the ``get_query_set()`` method and filter out any rows, Django
1128+If you override the ``get_queryset()`` method and filter out any rows, Django
1129 will return incorrect results. Don't do that. A manager that filters results
1130-in ``get_query_set()`` is not appropriate for use as an automatic manager.
1131+in ``get_queryset()`` is not appropriate for use as an automatic manager.
1132
1133 Set ``use_for_related_fields`` when you define the class
1134 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1135diff --git a/docs/topics/db/multi-db.txt b/docs/topics/db/multi-db.txt
1136index 8150e49..ae23c3d 100644
1137--- a/docs/topics/db/multi-db.txt
1138+++ b/docs/topics/db/multi-db.txt
1139@@ -506,19 +506,19 @@ solution is to use ``db_manager()``, like this::
1140
1141 ``db_manager()`` returns a copy of the manager bound to the database you specify.
1142
1143-Using ``get_query_set()`` with multiple databases
1144+Using ``get_queryset()`` with multiple databases
1145 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1146
1147-If you're overriding ``get_query_set()`` on your manager, be sure to
1148+If you're overriding ``get_queryset()`` on your manager, be sure to
1149 either call the method on the parent (using ``super()``) or do the
1150 appropriate handling of the ``_db`` attribute on the manager (a string
1151 containing the name of the database to use).
1152
1153 For example, if you want to return a custom ``QuerySet`` class from
1154-the ``get_query_set`` method, you could do this::
1155+the ``get_queryset`` method, you could do this::
1156
1157 class MyManager(models.Manager):
1158- def get_query_set(self):
1159+ def get_queryset(self):
1160 qs = CustomQuerySet(self.model)
1161 if self._db is not None:
1162 qs = qs.using(self._db)
1163@@ -548,9 +548,9 @@ multiple-database support::
1164 # Tell Django to delete objects from the 'other' database
1165 obj.delete(using=self.using)
1166
1167- def queryset(self, request):
1168+ def get_queryset(self, request):
1169 # Tell Django to look for objects on the 'other' database.
1170- return super(MultiDBModelAdmin, self).queryset(request).using(self.using)
1171+ return super(MultiDBModelAdmin, self).get_queryset(request).using(self.using)
1172
1173 def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
1174 # Tell Django to populate ForeignKey widgets using a query
1175@@ -573,9 +573,9 @@ Inlines can be handled in a similar fashion. They require three customized metho
1176 class MultiDBTabularInline(admin.TabularInline):
1177 using = 'other'
1178
1179- def queryset(self, request):
1180+ def get_queryset(self, request):
1181 # Tell Django to look for inline objects on the 'other' database.
1182- return super(MultiDBTabularInline, self).queryset(request).using(self.using)
1183+ return super(MultiDBTabularInline, self).get_queryset(request).using(self.using)
1184
1185 def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
1186 # Tell Django to populate ForeignKey widgets using a query
1187diff --git a/tests/admin_changelist/admin.py b/tests/admin_changelist/admin.py
1188index 5751d04..8387ba7 100644
1189--- a/tests/admin_changelist/admin.py
1190+++ b/tests/admin_changelist/admin.py
1191@@ -34,8 +34,8 @@ class ChildAdmin(admin.ModelAdmin):
1192 list_per_page = 10
1193 list_filter = ['parent', 'age']
1194
1195- def queryset(self, request):
1196- return super(ChildAdmin, self).queryset(request).select_related("parent__name")
1197+ def get_queryset(self, request):
1198+ return super(ChildAdmin, self).get_queryset(request).select_related("parent__name")
1199
1200
1201 class CustomPaginationAdmin(ChildAdmin):
1202@@ -46,8 +46,8 @@ class FilteredChildAdmin(admin.ModelAdmin):
1203 list_display = ['name', 'parent']
1204 list_per_page = 10
1205
1206- def queryset(self, request):
1207- return super(FilteredChildAdmin, self).queryset(request).filter(
1208+ def get_queryset(self, request):
1209+ return super(FilteredChildAdmin, self).get_queryset(request).filter(
1210 name__contains='filtered')
1211
1212
1213diff --git a/tests/admin_changelist/models.py b/tests/admin_changelist/models.py
1214index 4ba2f9c..786b438 100644
1215--- a/tests/admin_changelist/models.py
1216+++ b/tests/admin_changelist/models.py
1217@@ -74,8 +74,8 @@ class UnorderedObject(models.Model):
1218
1219
1220 class OrderedObjectManager(models.Manager):
1221- def get_query_set(self):
1222- return super(OrderedObjectManager, self).get_query_set().order_by('number')
1223+ def get_queryset(self):
1224+ return super(OrderedObjectManager, self).get_queryset().order_by('number')
1225
1226 class OrderedObject(models.Model):
1227 """
1228diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py
1229index bb39f22..5958792 100644
1230--- a/tests/admin_changelist/tests.py
1231+++ b/tests/admin_changelist/tests.py
1232@@ -39,8 +39,8 @@ class ChangeListTests(TestCase):
1233
1234 def test_select_related_preserved(self):
1235 """
1236- Regression test for #10348: ChangeList.get_query_set() shouldn't
1237- overwrite a custom select_related provided by ModelAdmin.queryset().
1238+ Regression test for #10348: ChangeList.get_queryset() shouldn't
1239+ overwrite a custom select_related provided by ModelAdmin.get_queryset().
1240 """
1241 m = ChildAdmin(Child, admin.site)
1242 request = self.factory.get('/child/')
1243diff --git a/tests/admin_filters/tests.py b/tests/admin_filters/tests.py
1244index 11f792e..f05e8e2 100644
1245--- a/tests/admin_filters/tests.py
1246+++ b/tests/admin_filters/tests.py
1247@@ -61,7 +61,7 @@ class DecadeListFilterWithFailingQueryset(DecadeListFilterWithTitleAndParameter)
1248 class DecadeListFilterWithQuerysetBasedLookups(DecadeListFilterWithTitleAndParameter):
1249
1250 def lookups(self, request, model_admin):
1251- qs = model_admin.queryset(request)
1252+ qs = model_admin.get_queryset(request)
1253 if qs.filter(year__gte=1980, year__lte=1989).exists():
1254 yield ('the 80s', "the 1980's")
1255 if qs.filter(year__gte=1990, year__lte=1999).exists():
1256@@ -86,7 +86,7 @@ class DepartmentListFilterLookupWithNonStringValue(SimpleListFilter):
1257 return sorted(set([
1258 (employee.department.id, # Intentionally not a string (Refs #19318)
1259 employee.department.code)
1260- for employee in model_admin.queryset(request).all()
1261+ for employee in model_admin.get_queryset(request).all()
1262 ]))
1263
1264 def queryset(self, request, queryset):
1265@@ -183,7 +183,7 @@ class ListFiltersTests(TestCase):
1266 changelist = self.get_changelist(request, Book, modeladmin)
1267
1268 # Make sure the correct queryset is returned
1269- queryset = changelist.get_query_set(request)
1270+ queryset = changelist.get_queryset(request)
1271 self.assertEqual(list(queryset), [self.django_book, self.djangonaut_book])
1272
1273 # Make sure the correct choice is selected
1274@@ -200,7 +200,7 @@ class ListFiltersTests(TestCase):
1275 changelist = self.get_changelist(request, Book, modeladmin)
1276
1277 # Make sure the correct queryset is returned
1278- queryset = changelist.get_query_set(request)
1279+ queryset = changelist.get_queryset(request)
1280 if (self.today.year, self.today.month) == (self.one_week_ago.year, self.one_week_ago.month):
1281 # In case one week ago is in the same month.
1282 self.assertEqual(list(queryset), [self.gipsy_book, self.django_book, self.djangonaut_book])
1283@@ -221,7 +221,7 @@ class ListFiltersTests(TestCase):
1284 changelist = self.get_changelist(request, Book, modeladmin)
1285
1286 # Make sure the correct queryset is returned
1287- queryset = changelist.get_query_set(request)
1288+ queryset = changelist.get_queryset(request)
1289 if self.today.year == self.one_week_ago.year:
1290 # In case one week ago is in the same year.
1291 self.assertEqual(list(queryset), [self.gipsy_book, self.django_book, self.djangonaut_book])
1292@@ -242,7 +242,7 @@ class ListFiltersTests(TestCase):
1293 changelist = self.get_changelist(request, Book, modeladmin)
1294
1295 # Make sure the correct queryset is returned
1296- queryset = changelist.get_query_set(request)
1297+ queryset = changelist.get_queryset(request)
1298 self.assertEqual(list(queryset), [self.gipsy_book, self.django_book, self.djangonaut_book])
1299
1300 # Make sure the correct choice is selected
1301@@ -266,7 +266,7 @@ class ListFiltersTests(TestCase):
1302 changelist = self.get_changelist(request, Book, modeladmin)
1303
1304 # Make sure the correct queryset is returned
1305- queryset = changelist.get_query_set(request)
1306+ queryset = changelist.get_queryset(request)
1307 self.assertEqual(list(queryset), [self.django_book])
1308
1309 # Make sure the last choice is None and is selected
1310@@ -293,7 +293,7 @@ class ListFiltersTests(TestCase):
1311 changelist = self.get_changelist(request, Book, modeladmin)
1312
1313 # Make sure the correct queryset is returned
1314- queryset = changelist.get_query_set(request)
1315+ queryset = changelist.get_queryset(request)
1316 self.assertEqual(list(queryset), [self.gipsy_book])
1317
1318 # Make sure the last choice is None and is selected
1319@@ -321,7 +321,7 @@ class ListFiltersTests(TestCase):
1320 changelist = self.get_changelist(request, Book, modeladmin)
1321
1322 # Make sure the correct queryset is returned
1323- queryset = changelist.get_query_set(request)
1324+ queryset = changelist.get_queryset(request)
1325 self.assertEqual(list(queryset), [self.django_book, self.bio_book, self.djangonaut_book])
1326
1327 # Make sure the last choice is None and is selected
1328@@ -349,7 +349,7 @@ class ListFiltersTests(TestCase):
1329 changelist = self.get_changelist(request, User, modeladmin)
1330
1331 # Make sure the correct queryset is returned
1332- queryset = changelist.get_query_set(request)
1333+ queryset = changelist.get_queryset(request)
1334 self.assertEqual(list(queryset), [self.lisa])
1335
1336 # Make sure the last choice is None and is selected
1337@@ -374,7 +374,7 @@ class ListFiltersTests(TestCase):
1338 changelist = self.get_changelist(request, User, modeladmin)
1339
1340 # Make sure the correct queryset is returned
1341- queryset = changelist.get_query_set(request)
1342+ queryset = changelist.get_queryset(request)
1343 self.assertEqual(list(queryset), [self.alfred])
1344
1345 # Make sure the last choice is None and is selected
1346@@ -410,7 +410,7 @@ class ListFiltersTests(TestCase):
1347 changelist = self.get_changelist(request, Book, modeladmin)
1348
1349 # Make sure the correct queryset is returned
1350- queryset = changelist.get_query_set(request)
1351+ queryset = changelist.get_queryset(request)
1352 self.assertEqual(list(queryset), [self.bio_book])
1353
1354 # Make sure the correct choice is selected
1355@@ -424,7 +424,7 @@ class ListFiltersTests(TestCase):
1356 changelist = self.get_changelist(request, Book, modeladmin)
1357
1358 # Make sure the correct queryset is returned
1359- queryset = changelist.get_query_set(request)
1360+ queryset = changelist.get_queryset(request)
1361 self.assertEqual(list(queryset), [self.gipsy_book, self.djangonaut_book])
1362
1363 # Make sure the correct choice is selected
1364@@ -438,7 +438,7 @@ class ListFiltersTests(TestCase):
1365 changelist = self.get_changelist(request, Book, modeladmin)
1366
1367 # Make sure the correct queryset is returned
1368- queryset = changelist.get_query_set(request)
1369+ queryset = changelist.get_queryset(request)
1370 self.assertEqual(list(queryset), [self.django_book])
1371
1372 # Make sure the correct choice is selected
1373@@ -457,7 +457,7 @@ class ListFiltersTests(TestCase):
1374 changelist = self.get_changelist(request, Book, modeladmin)
1375
1376 # Make sure the correct queryset is returned
1377- queryset = changelist.get_query_set(request)
1378+ queryset = changelist.get_queryset(request)
1379 self.assertEqual(list(queryset), list(Book.objects.all().order_by('-id')))
1380
1381 # Make sure the correct choice is selected
1382@@ -474,7 +474,7 @@ class ListFiltersTests(TestCase):
1383 changelist = self.get_changelist(request, Book, modeladmin)
1384
1385 # Make sure the correct queryset is returned
1386- queryset = changelist.get_query_set(request)
1387+ queryset = changelist.get_queryset(request)
1388 self.assertEqual(list(queryset), [])
1389
1390 # Make sure the correct choice is selected
1391@@ -491,7 +491,7 @@ class ListFiltersTests(TestCase):
1392 changelist = self.get_changelist(request, Book, modeladmin)
1393
1394 # Make sure the correct queryset is returned
1395- queryset = changelist.get_query_set(request)
1396+ queryset = changelist.get_queryset(request)
1397 self.assertEqual(list(queryset), [self.bio_book])
1398
1399 # Make sure the correct choice is selected
1400@@ -508,7 +508,7 @@ class ListFiltersTests(TestCase):
1401 changelist = self.get_changelist(request, Book, modeladmin)
1402
1403 # Make sure the correct queryset is returned
1404- queryset = changelist.get_query_set(request)
1405+ queryset = changelist.get_queryset(request)
1406 self.assertEqual(list(queryset), [self.gipsy_book, self.djangonaut_book])
1407
1408 # Make sure the correct choice is selected
1409@@ -525,7 +525,7 @@ class ListFiltersTests(TestCase):
1410 changelist = self.get_changelist(request, Book, modeladmin)
1411
1412 # Make sure the correct queryset is returned
1413- queryset = changelist.get_query_set(request)
1414+ queryset = changelist.get_queryset(request)
1415 self.assertEqual(list(queryset), [self.djangonaut_book])
1416
1417 # Make sure the correct choices are selected
1418@@ -615,7 +615,7 @@ class ListFiltersTests(TestCase):
1419 changelist = self.get_changelist(request, Book, modeladmin)
1420
1421 # Make sure the correct queryset is returned
1422- queryset = changelist.get_query_set(request)
1423+ queryset = changelist.get_queryset(request)
1424 self.assertEqual(list(queryset), [self.bio_book])
1425
1426 filterspec = changelist.get_filters(request)[0][-1]
1427@@ -637,7 +637,7 @@ class ListFiltersTests(TestCase):
1428 changelist = self.get_changelist(request, Book, modeladmin)
1429
1430 # Make sure the correct queryset is returned
1431- queryset = changelist.get_query_set(request)
1432+ queryset = changelist.get_queryset(request)
1433 self.assertEqual(list(queryset), [self.bio_book])
1434
1435 # Make sure the correct choice is selected
1436@@ -654,7 +654,7 @@ class ListFiltersTests(TestCase):
1437 changelist = self.get_changelist(request, Book, modeladmin)
1438
1439 # Make sure the correct queryset is returned
1440- queryset = changelist.get_query_set(request)
1441+ queryset = changelist.get_queryset(request)
1442 self.assertEqual(list(queryset), [self.bio_book])
1443
1444 # Make sure the correct choice is selected
1445@@ -676,7 +676,7 @@ class ListFiltersTests(TestCase):
1446 request = self.request_factory.get('/', {'department': self.john.pk})
1447 changelist = self.get_changelist(request, Employee, modeladmin)
1448
1449- queryset = changelist.get_query_set(request)
1450+ queryset = changelist.get_queryset(request)
1451
1452 self.assertEqual(list(queryset), [self.john])
1453
1454@@ -698,7 +698,7 @@ class ListFiltersTests(TestCase):
1455 changelist = self.get_changelist(request, Employee, modeladmin)
1456
1457 # Make sure the correct queryset is returned
1458- queryset = changelist.get_query_set(request)
1459+ queryset = changelist.get_queryset(request)
1460 self.assertEqual(list(queryset), [self.jack, self.john])
1461
1462 filterspec = changelist.get_filters(request)[0][-1]
1463@@ -723,7 +723,7 @@ class ListFiltersTests(TestCase):
1464 changelist = self.get_changelist(request, Employee, modeladmin)
1465
1466 # Make sure the correct queryset is returned
1467- queryset = changelist.get_query_set(request)
1468+ queryset = changelist.get_queryset(request)
1469 self.assertEqual(list(queryset), [self.john])
1470
1471 filterspec = changelist.get_filters(request)[0][-1]
1472diff --git a/tests/admin_ordering/tests.py b/tests/admin_ordering/tests.py
1473index faae834..26b720b 100644
1474--- a/tests/admin_ordering/tests.py
1475+++ b/tests/admin_ordering/tests.py
1476@@ -21,8 +21,8 @@ request.user = MockSuperUser()
1477
1478 class TestAdminOrdering(TestCase):
1479 """
1480- Let's make sure that ModelAdmin.queryset uses the ordering we define in
1481- ModelAdmin rather that ordering defined in the model's inner Meta
1482+ Let's make sure that ModelAdmin.get_queryset uses the ordering we define
1483+ in ModelAdmin rather that ordering defined in the model's inner Meta
1484 class.
1485 """
1486
1487@@ -41,7 +41,7 @@ class TestAdminOrdering(TestCase):
1488 class.
1489 """
1490 ma = ModelAdmin(Band, None)
1491- names = [b.name for b in ma.queryset(request)]
1492+ names = [b.name for b in ma.get_queryset(request)]
1493 self.assertEqual(['Aerosmith', 'Radiohead', 'Van Halen'], names)
1494
1495 def test_specified_ordering(self):
1496@@ -52,7 +52,7 @@ class TestAdminOrdering(TestCase):
1497 class BandAdmin(ModelAdmin):
1498 ordering = ('rank',) # default ordering is ('name',)
1499 ma = BandAdmin(Band, None)
1500- names = [b.name for b in ma.queryset(request)]
1501+ names = [b.name for b in ma.get_queryset(request)]
1502 self.assertEqual(['Radiohead', 'Van Halen', 'Aerosmith'], names)
1503
1504 def test_dynamic_ordering(self):
1505@@ -64,17 +64,17 @@ class TestAdminOrdering(TestCase):
1506 request = self.request_factory.get('/')
1507 request.user = super_user
1508 ma = DynOrderingBandAdmin(Band, None)
1509- names = [b.name for b in ma.queryset(request)]
1510+ names = [b.name for b in ma.get_queryset(request)]
1511 self.assertEqual(['Radiohead', 'Van Halen', 'Aerosmith'], names)
1512 request.user = other_user
1513- names = [b.name for b in ma.queryset(request)]
1514+ names = [b.name for b in ma.get_queryset(request)]
1515 self.assertEqual(['Aerosmith', 'Radiohead', 'Van Halen'], names)
1516
1517
1518 class TestInlineModelAdminOrdering(TestCase):
1519 """
1520- Let's make sure that InlineModelAdmin.queryset uses the ordering we define
1521- in InlineModelAdmin.
1522+ Let's make sure that InlineModelAdmin.get_queryset uses the ordering we
1523+ define in InlineModelAdmin.
1524 """
1525
1526 def setUp(self):
1527@@ -94,7 +94,7 @@ class TestInlineModelAdminOrdering(TestCase):
1528 class.
1529 """
1530 inline = SongInlineDefaultOrdering(self.b, None)
1531- names = [s.name for s in inline.queryset(request)]
1532+ names = [s.name for s in inline.get_queryset(request)]
1533 self.assertEqual(['Dude (Looks Like a Lady)', 'Jaded', 'Pink'], names)
1534
1535 def test_specified_ordering(self):
1536@@ -102,5 +102,5 @@ class TestInlineModelAdminOrdering(TestCase):
1537 Let's check with ordering set to something different than the default.
1538 """
1539 inline = SongInlineNewOrdering(self.b, None)
1540- names = [s.name for s in inline.queryset(request)]
1541+ names = [s.name for s in inline.get_queryset(request)]
1542 self.assertEqual(['Jaded', 'Pink', 'Dude (Looks Like a Lady)'], names)
1543diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py
1544index d434896..06451ab 100644
1545--- a/tests/admin_views/admin.py
1546+++ b/tests/admin_views/admin.py
1547@@ -177,10 +177,10 @@ class PersonAdmin(admin.ModelAdmin):
1548 return super(PersonAdmin, self).get_changelist_formset(request,
1549 formset=BasePersonModelFormSet, **kwargs)
1550
1551- def queryset(self, request):
1552+ def get_queryset(self, request):
1553 # Order by a field that isn't in list display, to be able to test
1554 # whether ordering is preserved.
1555- return super(PersonAdmin, self).queryset(request).order_by('age')
1556+ return super(PersonAdmin, self).get_queryset(request).order_by('age')
1557
1558
1559 class FooAccount(Account):
1560@@ -283,8 +283,8 @@ class ParentAdmin(admin.ModelAdmin):
1561
1562
1563 class EmptyModelAdmin(admin.ModelAdmin):
1564- def queryset(self, request):
1565- return super(EmptyModelAdmin, self).queryset(request).filter(pk__gt=1)
1566+ def get_queryset(self, request):
1567+ return super(EmptyModelAdmin, self).get_queryset(request).filter(pk__gt=1)
1568
1569
1570 class OldSubscriberAdmin(admin.ModelAdmin):
1571@@ -427,7 +427,7 @@ class PostAdmin(admin.ModelAdmin):
1572
1573
1574 class CustomChangeList(ChangeList):
1575- def get_query_set(self, request):
1576+ def get_queryset(self, request):
1577 return self.root_query_set.filter(pk=9999) # Does not exist
1578
1579
1580@@ -452,52 +452,52 @@ class FoodDeliveryAdmin(admin.ModelAdmin):
1581
1582 class CoverLetterAdmin(admin.ModelAdmin):
1583 """
1584- A ModelAdmin with a custom queryset() method that uses defer(), to test
1585+ A ModelAdmin with a custom get_queryset() method that uses defer(), to test
1586 verbose_name display in messages shown after adding/editing CoverLetter
1587 instances.
1588 Note that the CoverLetter model defines a __unicode__ method.
1589 For testing fix for ticket #14529.
1590 """
1591
1592- def queryset(self, request):
1593- return super(CoverLetterAdmin, self).queryset(request).defer('date_written')
1594+ def get_queryset(self, request):
1595+ return super(CoverLetterAdmin, self).get_queryset(request).defer('date_written')
1596
1597
1598 class PaperAdmin(admin.ModelAdmin):
1599 """
1600- A ModelAdmin with a custom queryset() method that uses only(), to test
1601+ A ModelAdmin with a custom get_queryset() method that uses only(), to test
1602 verbose_name display in messages shown after adding/editing Paper
1603 instances.
1604 For testing fix for ticket #14529.
1605 """
1606
1607- def queryset(self, request):
1608- return super(PaperAdmin, self).queryset(request).only('title')
1609+ def get_queryset(self, request):
1610+ return super(PaperAdmin, self).get_queryset(request).only('title')
1611
1612
1613 class ShortMessageAdmin(admin.ModelAdmin):
1614 """
1615- A ModelAdmin with a custom queryset() method that uses defer(), to test
1616+ A ModelAdmin with a custom get_queryset() method that uses defer(), to test
1617 verbose_name display in messages shown after adding/editing ShortMessage
1618 instances.
1619 For testing fix for ticket #14529.
1620 """
1621
1622- def queryset(self, request):
1623- return super(ShortMessageAdmin, self).queryset(request).defer('timestamp')
1624+ def get_queryset(self, request):
1625+ return super(ShortMessageAdmin, self).get_queryset(request).defer('timestamp')
1626
1627
1628 class TelegramAdmin(admin.ModelAdmin):
1629 """
1630- A ModelAdmin with a custom queryset() method that uses only(), to test
1631+ A ModelAdmin with a custom get_queryset() method that uses only(), to test
1632 verbose_name display in messages shown after adding/editing Telegram
1633 instances.
1634 Note that the Telegram model defines a __unicode__ method.
1635 For testing fix for ticket #14529.
1636 """
1637
1638- def queryset(self, request):
1639- return super(TelegramAdmin, self).queryset(request).only('title')
1640+ def get_queryset(self, request):
1641+ return super(TelegramAdmin, self).get_queryset(request).only('title')
1642
1643
1644 class StoryForm(forms.ModelForm):
1645diff --git a/tests/admin_views/customadmin.py b/tests/admin_views/customadmin.py
1646index d69d690..c204b81 100644
1647--- a/tests/admin_views/customadmin.py
1648+++ b/tests/admin_views/customadmin.py
1649@@ -35,8 +35,8 @@ class Admin2(admin.AdminSite):
1650
1651 class UserLimitedAdmin(UserAdmin):
1652 # used for testing password change on a user not in queryset
1653- def queryset(self, request):
1654- qs = super(UserLimitedAdmin, self).queryset(request)
1655+ def get_queryset(self, request):
1656+ qs = super(UserLimitedAdmin, self).get_queryset(request)
1657 return qs.filter(is_superuser=False)
1658
1659
1660diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
1661index 0bcfc0c..3027a49 100644
1662--- a/tests/admin_views/tests.py
1663+++ b/tests/admin_views/tests.py
1664@@ -282,7 +282,7 @@ class AdminViewBasicTest(TestCase):
1665 """
1666 If no ordering is defined in `ModelAdmin.ordering` or in the query
1667 string, then the underlying order of the queryset should not be
1668- changed, even if it is defined in `Modeladmin.queryset()`.
1669+ changed, even if it is defined in `Modeladmin.get_queryset()`.
1670 Refs #11868, #7309.
1671 """
1672 p1 = Person.objects.create(name="Amy", gender=1, alive=True, age=80)
1673@@ -2574,7 +2574,7 @@ class AdminCustomQuerysetTest(TestCase):
1674 self.assertEqual(response.status_code, 404)
1675
1676 def test_add_model_modeladmin_defer_qs(self):
1677- # Test for #14529. defer() is used in ModelAdmin.queryset()
1678+ # Test for #14529. defer() is used in ModelAdmin.get_queryset()
1679
1680 # model has __unicode__ method
1681 self.assertEqual(CoverLetter.objects.count(), 0)
1682@@ -2613,7 +2613,7 @@ class AdminCustomQuerysetTest(TestCase):
1683 )
1684
1685 def test_add_model_modeladmin_only_qs(self):
1686- # Test for #14529. only() is used in ModelAdmin.queryset()
1687+ # Test for #14529. only() is used in ModelAdmin.get_queryset()
1688
1689 # model has __unicode__ method
1690 self.assertEqual(Telegram.objects.count(), 0)
1691@@ -2652,7 +2652,7 @@ class AdminCustomQuerysetTest(TestCase):
1692 )
1693
1694 def test_edit_model_modeladmin_defer_qs(self):
1695- # Test for #14529. defer() is used in ModelAdmin.queryset()
1696+ # Test for #14529. defer() is used in ModelAdmin.get_queryset()
1697
1698 # model has __unicode__ method
1699 cl = CoverLetter.objects.create(author="John Doe")
1700@@ -2699,7 +2699,7 @@ class AdminCustomQuerysetTest(TestCase):
1701 )
1702
1703 def test_edit_model_modeladmin_only_qs(self):
1704- # Test for #14529. only() is used in ModelAdmin.queryset()
1705+ # Test for #14529. only() is used in ModelAdmin.get_queryset()
1706
1707 # model has __unicode__ method
1708 t = Telegram.objects.create(title="Frist Telegram")
1709diff --git a/tests/admin_widgets/models.py b/tests/admin_widgets/models.py
1710index 2977b86..ae19d58 100644
1711--- a/tests/admin_widgets/models.py
1712+++ b/tests/admin_widgets/models.py
1713@@ -37,8 +37,8 @@ class Album(models.Model):
1714 return self.name
1715
1716 class HiddenInventoryManager(models.Manager):
1717- def get_query_set(self):
1718- return super(HiddenInventoryManager, self).get_query_set().filter(hidden=False)
1719+ def get_queryset(self):
1720+ return super(HiddenInventoryManager, self).get_queryset().filter(hidden=False)
1721
1722 @python_2_unicode_compatible
1723 class Inventory(models.Model):
1724diff --git a/tests/custom_managers/models.py b/tests/custom_managers/models.py
1725index de7c177..2f5e62f 100644
1726--- a/tests/custom_managers/models.py
1727+++ b/tests/custom_managers/models.py
1728@@ -30,11 +30,11 @@ class Person(models.Model):
1729 def __str__(self):
1730 return "%s %s" % (self.first_name, self.last_name)
1731
1732-# An example of a custom manager that sets get_query_set().
1733+# An example of a custom manager that sets get_queryset().
1734
1735 class PublishedBookManager(models.Manager):
1736- def get_query_set(self):
1737- return super(PublishedBookManager, self).get_query_set().filter(is_published=True)
1738+ def get_queryset(self):
1739+ return super(PublishedBookManager, self).get_queryset().filter(is_published=True)
1740
1741 @python_2_unicode_compatible
1742 class Book(models.Model):
1743@@ -50,8 +50,8 @@ class Book(models.Model):
1744 # An example of providing multiple custom managers.
1745
1746 class FastCarManager(models.Manager):
1747- def get_query_set(self):
1748- return super(FastCarManager, self).get_query_set().filter(top_speed__gt=150)
1749+ def get_queryset(self):
1750+ return super(FastCarManager, self).get_queryset().filter(top_speed__gt=150)
1751
1752 @python_2_unicode_compatible
1753 class Car(models.Model):
1754diff --git a/tests/custom_managers_regress/models.py b/tests/custom_managers_regress/models.py
1755index 71073f0..95cf6e8 100644
1756--- a/tests/custom_managers_regress/models.py
1757+++ b/tests/custom_managers_regress/models.py
1758@@ -10,8 +10,8 @@ class RestrictedManager(models.Manager):
1759 """
1760 A manager that filters out non-public instances.
1761 """
1762- def get_query_set(self):
1763- return super(RestrictedManager, self).get_query_set().filter(is_public=True)
1764+ def get_queryset(self):
1765+ return super(RestrictedManager, self).get_queryset().filter(is_public=True)
1766
1767 @python_2_unicode_compatible
1768 class RelatedModel(models.Model):
1769diff --git a/tests/deprecation/__init__.py b/tests/deprecation/__init__.py
1770new file mode 100644
1771index 0000000..e69de29
1772diff --git a/tests/deprecation/models.py b/tests/deprecation/models.py
1773new file mode 100644
1774index 0000000..e69de29
1775diff --git a/tests/deprecation/tests.py b/tests/deprecation/tests.py
1776new file mode 100644
1777index 0000000..6317e54
1778--- /dev/null
1779+++ b/tests/deprecation/tests.py
1780@@ -0,0 +1,172 @@
1781+from __future__ import unicode_literals
1782+import warnings
1783+
1784+from django.test.testcases import SimpleTestCase
1785+from django.utils import six
1786+from django.utils.deprecation import RenameMethodsBase
1787+
1788+
1789+class RenameManagerMethods(RenameMethodsBase):
1790+ renamed_methods = (
1791+ ('old', 'new'),
1792+ )
1793+
1794+
1795+class RenameMethodsTests(SimpleTestCase):
1796+ """
1797+ Tests the `RenameMethodsBase` type introduced to rename `get_query_set`
1798+ to `get_queryset` across the code base following #15363.
1799+ """
1800+
1801+ def test_class_definition_warnings(self):
1802+ """
1803+ Ensure a warning is raised upon class definition to suggest renaming
1804+ the faulty method.
1805+ """
1806+ with warnings.catch_warnings(record=True) as recorded:
1807+ warnings.simplefilter('always')
1808+ class Manager(six.with_metaclass(RenameManagerMethods)):
1809+ def old(self):
1810+ pass
1811+ self.assertEqual(len(recorded), 1)
1812+ msg = str(recorded[0].message)
1813+ self.assertEqual(msg,
1814+ '`Manager.old` method should be renamed `new`.')
1815+
1816+ def test_get_new_defined(self):
1817+ """
1818+ Ensure `old` complains and not `new` when only `new` is defined.
1819+ """
1820+ with warnings.catch_warnings(record=True) as recorded:
1821+ warnings.simplefilter('ignore')
1822+ class Manager(six.with_metaclass(RenameManagerMethods)):
1823+ def new(self):
1824+ pass
1825+ warnings.simplefilter('always')
1826+ manager = Manager()
1827+ manager.new()
1828+ self.assertEqual(len(recorded), 0)
1829+ manager.old()
1830+ self.assertEqual(len(recorded), 1)
1831+ msg = str(recorded.pop().message)
1832+ self.assertEqual(msg,
1833+ '`Manager.old` is deprecated, use `new` instead.')
1834+
1835+ def test_get_old_defined(self):
1836+ """
1837+ Ensure `old` complains when only `old` is defined.
1838+ """
1839+ with warnings.catch_warnings(record=True) as recorded:
1840+ warnings.simplefilter('ignore')
1841+ class Manager(six.with_metaclass(RenameManagerMethods)):
1842+ def old(self):
1843+ pass
1844+ warnings.simplefilter('always')
1845+ manager = Manager()
1846+ manager.new()
1847+ self.assertEqual(len(recorded), 1)
1848+ msg = str(recorded.pop().message)
1849+ self.assertEqual(msg,
1850+ '`Manager.old` is deprecated, use `new` instead.')
1851+ manager.old()
1852+ self.assertEqual(len(recorded), 1)
1853+ msg = str(recorded.pop().message)
1854+ self.assertEqual(msg,
1855+ '`Manager.old` is deprecated, use `new` instead.')
1856+
1857+ def test_deprecated_subclass_renamed(self):
1858+ """
1859+ Ensure the correct warnings are raised when a class that didn't rename
1860+ `old` subclass one that did.
1861+ """
1862+ with warnings.catch_warnings(record=True) as recorded:
1863+ warnings.simplefilter('ignore')
1864+ class Renamed(six.with_metaclass(RenameManagerMethods)):
1865+ def new(self):
1866+ pass
1867+ class Deprecated(Renamed):
1868+ def old(self):
1869+ super(Deprecated, self).old()
1870+ warnings.simplefilter('always')
1871+ deprecated = Deprecated()
1872+ deprecated.new()
1873+ self.assertEqual(len(recorded), 2)
1874+ msgs = [str(warning.message) for warning in recorded]
1875+ self.assertEqual(msgs, [
1876+ '`Deprecated.old` is deprecated, use `new` instead.',
1877+ '`Renamed.old` is deprecated, use `new` instead.',
1878+ ])
1879+ recorded[:] = []
1880+ deprecated.old()
1881+ self.assertEqual(len(recorded), 2)
1882+ msgs = [str(warning.message) for warning in recorded]
1883+ self.assertEqual(msgs, [
1884+ '`Deprecated.old` is deprecated, use `new` instead.',
1885+ '`Renamed.old` is deprecated, use `new` instead.',
1886+ ])
1887+
1888+ def test_renamed_subclass_deprecated(self):
1889+ """
1890+ Ensure the correct warnings are raised when a class that renamed
1891+ `old` subclass one that didn't.
1892+ """
1893+ with warnings.catch_warnings(record=True) as recorded:
1894+ warnings.simplefilter('ignore')
1895+ class Deprecated(six.with_metaclass(RenameManagerMethods)):
1896+ def old(self):
1897+ pass
1898+ class Renamed(Deprecated):
1899+ def new(self):
1900+ super(Renamed, self).new()
1901+ warnings.simplefilter('always')
1902+ renamed = Renamed()
1903+ renamed.new()
1904+ self.assertEqual(len(recorded), 1)
1905+ msg = str(recorded.pop().message)
1906+ self.assertEqual(msg,
1907+ '`Deprecated.old` is deprecated, use `new` instead.')
1908+ recorded[:] = []
1909+ renamed.old()
1910+ self.assertEqual(len(recorded), 2)
1911+ msgs = [str(warning.message) for warning in recorded]
1912+ self.assertEqual(msgs, [
1913+ '`Renamed.old` is deprecated, use `new` instead.',
1914+ '`Deprecated.old` is deprecated, use `new` instead.',
1915+ ])
1916+
1917+ def test_deprecated_subclass_renamed_and_mixins(self):
1918+ """
1919+ Ensure the correct warnings are raised when a subclass inherit from a
1920+ class that renamed `old` and mixins that may or may not have renamed
1921+ `new`.
1922+ """
1923+ with warnings.catch_warnings(record=True) as recorded:
1924+ warnings.simplefilter('ignore')
1925+ class Renamed(six.with_metaclass(RenameManagerMethods)):
1926+ def new(self):
1927+ pass
1928+ class RenamedMixin(object):
1929+ def new(self):
1930+ super(RenamedMixin, self).new()
1931+ class DeprecatedMixin(object):
1932+ def old(self):
1933+ super(DeprecatedMixin, self).old()
1934+ class Deprecated(DeprecatedMixin, RenamedMixin, Renamed):
1935+ pass
1936+ warnings.simplefilter('always')
1937+ deprecated = Deprecated()
1938+ deprecated.new()
1939+ self.assertEqual(len(recorded), 2)
1940+ msgs = [str(warning.message) for warning in recorded]
1941+ self.assertEqual(msgs, [
1942+ '`DeprecatedMixin.old` is deprecated, use `new` instead.',
1943+ '`RenamedMixin.old` is deprecated, use `new` instead.',
1944+ ])
1945+ recorded[:] = []
1946+ deprecated.old()
1947+ self.assertEqual(len(recorded), 2)
1948+ msgs = [str(warning.message) for warning in recorded]
1949+ self.assertEqual(msgs, [
1950+ '`DeprecatedMixin.old` is deprecated, use `new` instead.',
1951+ '`RenamedMixin.old` is deprecated, use `new` instead.',
1952+ ])
1953diff --git a/tests/fixtures/models.py b/tests/fixtures/models.py
1954index 8bd3501..976716f 100644
1955--- a/tests/fixtures/models.py
1956+++ b/tests/fixtures/models.py
1957@@ -78,8 +78,8 @@ class Person(models.Model):
1958 return (self.name,)
1959
1960 class SpyManager(PersonManager):
1961- def get_query_set(self):
1962- return super(SpyManager, self).get_query_set().filter(cover_blown=False)
1963+ def get_queryset(self):
1964+ return super(SpyManager, self).get_queryset().filter(cover_blown=False)
1965
1966 class Spy(Person):
1967 objects = SpyManager()
1968diff --git a/tests/generic_relations/models.py b/tests/generic_relations/models.py
1969index 18d7623..34dc8d3 100644
1970--- a/tests/generic_relations/models.py
1971+++ b/tests/generic_relations/models.py
1972@@ -88,8 +88,8 @@ class Mineral(models.Model):
1973 return self.name
1974
1975 class GeckoManager(models.Manager):
1976- def get_query_set(self):
1977- return super(GeckoManager, self).get_query_set().filter(has_tail=True)
1978+ def get_queryset(self):
1979+ return super(GeckoManager, self).get_queryset().filter(has_tail=True)
1980
1981 class Gecko(models.Model):
1982 has_tail = models.BooleanField()
1983diff --git a/tests/get_object_or_404/models.py b/tests/get_object_or_404/models.py
1984index bda0605..bb9aa60 100644
1985--- a/tests/get_object_or_404/models.py
1986+++ b/tests/get_object_or_404/models.py
1987@@ -22,8 +22,8 @@ class Author(models.Model):
1988 return self.name
1989
1990 class ArticleManager(models.Manager):
1991- def get_query_set(self):
1992- return super(ArticleManager, self).get_query_set().filter(authors__name__icontains='sir')
1993+ def get_queryset(self):
1994+ return super(ArticleManager, self).get_queryset().filter(authors__name__icontains='sir')
1995
1996 @python_2_unicode_compatible
1997 class Article(models.Model):
1998diff --git a/tests/managers_regress/models.py b/tests/managers_regress/models.py
1999index d72970d..d8dd22e 100644
2000--- a/tests/managers_regress/models.py
2001+++ b/tests/managers_regress/models.py
2002@@ -7,18 +7,18 @@ from django.utils.encoding import python_2_unicode_compatible
2003
2004
2005 class OnlyFred(models.Manager):
2006- def get_query_set(self):
2007- return super(OnlyFred, self).get_query_set().filter(name='fred')
2008+ def get_queryset(self):
2009+ return super(OnlyFred, self).get_queryset().filter(name='fred')
2010
2011
2012 class OnlyBarney(models.Manager):
2013- def get_query_set(self):
2014- return super(OnlyBarney, self).get_query_set().filter(name='barney')
2015+ def get_queryset(self):
2016+ return super(OnlyBarney, self).get_queryset().filter(name='barney')
2017
2018
2019 class Value42(models.Manager):
2020- def get_query_set(self):
2021- return super(Value42, self).get_query_set().filter(value=42)
2022+ def get_queryset(self):
2023+ return super(Value42, self).get_queryset().filter(value=42)
2024
2025
2026 class AbstractBase1(models.Model):
2027diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py
2028index b0a1812..2f3eddd 100644
2029--- a/tests/modeladmin/tests.py
2030+++ b/tests/modeladmin/tests.py
2031@@ -1074,7 +1074,7 @@ class ValidationTests(unittest.TestCase):
2032 return 'awesomeness'
2033 def get_choices(self, request):
2034 return (('bit', 'A bit awesome'), ('very', 'Very awesome'), )
2035- def get_query_set(self, cl, qs):
2036+ def get_queryset(self, cl, qs):
2037 return qs
2038
2039 class ValidationTestModelAdmin(ModelAdmin):
2040diff --git a/tests/prefetch_related/models.py b/tests/prefetch_related/models.py
2041index e58997d..81c5698 100644
2042--- a/tests/prefetch_related/models.py
2043+++ b/tests/prefetch_related/models.py
2044@@ -87,8 +87,8 @@ class Qualification(models.Model):
2045
2046
2047 class TeacherManager(models.Manager):
2048- def get_query_set(self):
2049- return super(TeacherManager, self).get_query_set().prefetch_related('qualifications')
2050+ def get_queryset(self):
2051+ return super(TeacherManager, self).get_queryset().prefetch_related('qualifications')
2052
2053
2054 @python_2_unicode_compatible
2055diff --git a/tests/proxy_models/models.py b/tests/proxy_models/models.py
2056index 6c962aa..ffb3665 100644
2057--- a/tests/proxy_models/models.py
2058+++ b/tests/proxy_models/models.py
2059@@ -10,12 +10,12 @@ from django.utils.encoding import python_2_unicode_compatible
2060 # A couple of managers for testing managing overriding in proxy model cases.
2061
2062 class PersonManager(models.Manager):
2063- def get_query_set(self):
2064- return super(PersonManager, self).get_query_set().exclude(name="fred")
2065+ def get_queryset(self):
2066+ return super(PersonManager, self).get_queryset().exclude(name="fred")
2067
2068 class SubManager(models.Manager):
2069- def get_query_set(self):
2070- return super(SubManager, self).get_query_set().exclude(name="wilma")
2071+ def get_queryset(self):
2072+ return super(SubManager, self).get_queryset().exclude(name="wilma")
2073
2074 @python_2_unicode_compatible
2075 class Person(models.Model):
2076diff --git a/tests/queries/models.py b/tests/queries/models.py
2077index 28c8585..c025308 100644
2078--- a/tests/queries/models.py
2079+++ b/tests/queries/models.py
2080@@ -176,8 +176,8 @@ class LoopZ(models.Model):
2081
2082 # A model and custom default manager combination.
2083 class CustomManager(models.Manager):
2084- def get_query_set(self):
2085- qs = super(CustomManager, self).get_query_set()
2086+ def get_queryset(self):
2087+ qs = super(CustomManager, self).get_queryset()
2088 return qs.filter(public=True, tag__name='t1')
2089
2090 @python_2_unicode_compatible
2091@@ -197,8 +197,8 @@ class Detail(models.Model):
2092 data = models.CharField(max_length=10)
2093
2094 class MemberManager(models.Manager):
2095- def get_query_set(self):
2096- return super(MemberManager, self).get_query_set().select_related("details")
2097+ def get_queryset(self):
2098+ return super(MemberManager, self).get_queryset().select_related("details")
2099
2100 class Member(models.Model):
2101 name = models.CharField(max_length=10)
2102diff --git a/tests/reverse_single_related/models.py b/tests/reverse_single_related/models.py
2103index 898be84..30ba345 100644
2104--- a/tests/reverse_single_related/models.py
2105+++ b/tests/reverse_single_related/models.py
2106@@ -2,8 +2,8 @@ from django.db import models
2107
2108
2109 class SourceManager(models.Manager):
2110- def get_query_set(self):
2111- return super(SourceManager, self).get_query_set().filter(is_public=True)
2112+ def get_queryset(self):
2113+ return super(SourceManager, self).get_queryset().filter(is_public=True)
2114
2115 class Source(models.Model):
2116 is_public = models.BooleanField()
Back to Top