Ticket #15363: ticket-15363-deprecated-metaclass.diff
File ticket-15363-deprecated-metaclass.diff, 59.3 KB (added by , 12 years ago) |
---|
-
django/contrib/admin/options.py
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 8de3112..f429af5 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: -
django/contrib/admin/views/main.py
diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index 4b296b3..c45d5d8 100644
a b from django.core.paginator import InvalidPage 6 6 from django.core.urlresolvers import reverse 7 7 from django.db import models 8 8 from django.db.models.fields import FieldDoesNotExist 9 from django.utils import six 9 10 from django.utils.datastructures import SortedDict 11 from django.utils.deprecation import DeprecatedGetQuerySet 10 12 from django.utils.encoding import force_str, force_text 11 13 from django.utils.translation import ugettext, ugettext_lazy 12 14 from django.utils.http import urlencode … … IGNORED_PARAMS = ( 33 35 EMPTY_CHANGELIST_VALUE = ugettext_lazy('(None)') 34 36 35 37 36 class ChangeList( object):38 class ChangeList(six.with_metaclass(DeprecatedGetQuerySet)): 37 39 def __init__(self, request, model, list_display, list_display_links, 38 40 list_filter, date_hierarchy, search_fields, list_select_related, 39 41 list_per_page, list_max_show_all, list_editable, model_admin): … … 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) -
django/contrib/comments/managers.py
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 -
django/contrib/comments/templatetags/comments.py
diff --git a/django/contrib/comments/templatetags/comments.py b/django/contrib/comments/templatetags/comments.py index 4d4eb23..900c08f 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 import six 7 from django.utils.deprecation import DeprecatedGetQuerySet 6 8 from django.utils.encoding import smart_text 7 9 8 10 register = template.Library() 9 11 10 class BaseCommentNode(template.Node): 12 13 class BaseCommentNode(six.with_metaclass(DeprecatedGetQuerySet, template.Node)): 11 14 """ 12 15 Base helper class (abstract) for handling the get_comment_* template tags. 13 16 Looks a bit strange, but the subclasses below should make this a bit more … … 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) -
django/contrib/contenttypes/generic.py
diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py index d849d16..bef19dc 100644
a b def create_generic_related_manager(superclass): 316 316 '%s__exact' % object_id_field_name: instance._get_pk_val(), 317 317 } 318 318 319 def get_query _set(self):319 def get_queryset(self): 320 320 try: 321 321 return self.instance._prefetched_objects_cache[self.prefetch_cache_name] 322 322 except (AttributeError, KeyError): 323 323 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)324 return super(GenericRelatedObjectManager, self).get_queryset().using(db).filter(**self.core_filters) 325 325 326 326 def get_prefetch_query_set(self, instances): 327 327 db = self._db or router.db_for_read(self.model, instance=instances[0]) … … def create_generic_related_manager(superclass): 330 330 '%s__in' % self.object_id_field_name: 331 331 set(obj._get_pk_val() for obj in instances) 332 332 } 333 qs = super(GenericRelatedObjectManager, self).get_query _set().using(db).filter(**query)333 qs = super(GenericRelatedObjectManager, self).get_queryset().using(db).filter(**query) 334 334 # We (possibly) need to convert object IDs to the type of the 335 335 # instances' PK in order to match up instances: 336 336 object_id_converter = instances[0]._meta.pk.to_python -
django/contrib/gis/db/models/manager.py
diff --git a/django/contrib/gis/db/models/manager.py b/django/contrib/gis/db/models/manager.py index 61fb821..bbcbb57 100644
a b 1 1 from django.db.models.manager import Manager 2 2 from django.contrib.gis.db.models.query import GeoQuerySet 3 3 4 4 5 class GeoManager(Manager): 5 6 "Overrides Manager to return Geographic QuerySets." 6 7 … … class GeoManager(Manager): 9 10 # properly. 10 11 use_for_related_fields = True 11 12 12 def get_query _set(self):13 def get_queryset(self): 13 14 return GeoQuerySet(self.model, using=self._db) 14 15 15 16 def area(self, *args, **kwargs): 16 return self.get_query _set().area(*args, **kwargs)17 return self.get_queryset().area(*args, **kwargs) 17 18 18 19 def centroid(self, *args, **kwargs): 19 return self.get_query _set().centroid(*args, **kwargs)20 return self.get_queryset().centroid(*args, **kwargs) 20 21 21 22 def collect(self, *args, **kwargs): 22 return self.get_query _set().collect(*args, **kwargs)23 return self.get_queryset().collect(*args, **kwargs) 23 24 24 25 def difference(self, *args, **kwargs): 25 return self.get_query _set().difference(*args, **kwargs)26 return self.get_queryset().difference(*args, **kwargs) 26 27 27 28 def distance(self, *args, **kwargs): 28 return self.get_query _set().distance(*args, **kwargs)29 return self.get_queryset().distance(*args, **kwargs) 29 30 30 31 def envelope(self, *args, **kwargs): 31 return self.get_query _set().envelope(*args, **kwargs)32 return self.get_queryset().envelope(*args, **kwargs) 32 33 33 34 def extent(self, *args, **kwargs): 34 return self.get_query _set().extent(*args, **kwargs)35 return self.get_queryset().extent(*args, **kwargs) 35 36 36 37 def extent3d(self, *args, **kwargs): 37 return self.get_query _set().extent3d(*args, **kwargs)38 return self.get_queryset().extent3d(*args, **kwargs) 38 39 39 40 def force_rhr(self, *args, **kwargs): 40 return self.get_query _set().force_rhr(*args, **kwargs)41 return self.get_queryset().force_rhr(*args, **kwargs) 41 42 42 43 def geohash(self, *args, **kwargs): 43 return self.get_query _set().geohash(*args, **kwargs)44 return self.get_queryset().geohash(*args, **kwargs) 44 45 45 46 def geojson(self, *args, **kwargs): 46 return self.get_query _set().geojson(*args, **kwargs)47 return self.get_queryset().geojson(*args, **kwargs) 47 48 48 49 def gml(self, *args, **kwargs): 49 return self.get_query _set().gml(*args, **kwargs)50 return self.get_queryset().gml(*args, **kwargs) 50 51 51 52 def intersection(self, *args, **kwargs): 52 return self.get_query _set().intersection(*args, **kwargs)53 return self.get_queryset().intersection(*args, **kwargs) 53 54 54 55 def kml(self, *args, **kwargs): 55 return self.get_query _set().kml(*args, **kwargs)56 return self.get_queryset().kml(*args, **kwargs) 56 57 57 58 def length(self, *args, **kwargs): 58 return self.get_query _set().length(*args, **kwargs)59 return self.get_queryset().length(*args, **kwargs) 59 60 60 61 def make_line(self, *args, **kwargs): 61 return self.get_query _set().make_line(*args, **kwargs)62 return self.get_queryset().make_line(*args, **kwargs) 62 63 63 64 def mem_size(self, *args, **kwargs): 64 return self.get_query _set().mem_size(*args, **kwargs)65 return self.get_queryset().mem_size(*args, **kwargs) 65 66 66 67 def num_geom(self, *args, **kwargs): 67 return self.get_query _set().num_geom(*args, **kwargs)68 return self.get_queryset().num_geom(*args, **kwargs) 68 69 69 70 def num_points(self, *args, **kwargs): 70 return self.get_query _set().num_points(*args, **kwargs)71 return self.get_queryset().num_points(*args, **kwargs) 71 72 72 73 def perimeter(self, *args, **kwargs): 73 return self.get_query _set().perimeter(*args, **kwargs)74 return self.get_queryset().perimeter(*args, **kwargs) 74 75 75 76 def point_on_surface(self, *args, **kwargs): 76 return self.get_query _set().point_on_surface(*args, **kwargs)77 return self.get_queryset().point_on_surface(*args, **kwargs) 77 78 78 79 def reverse_geom(self, *args, **kwargs): 79 return self.get_query _set().reverse_geom(*args, **kwargs)80 return self.get_queryset().reverse_geom(*args, **kwargs) 80 81 81 82 def scale(self, *args, **kwargs): 82 return self.get_query _set().scale(*args, **kwargs)83 return self.get_queryset().scale(*args, **kwargs) 83 84 84 85 def snap_to_grid(self, *args, **kwargs): 85 return self.get_query _set().snap_to_grid(*args, **kwargs)86 return self.get_queryset().snap_to_grid(*args, **kwargs) 86 87 87 88 def svg(self, *args, **kwargs): 88 return self.get_query _set().svg(*args, **kwargs)89 return self.get_queryset().svg(*args, **kwargs) 89 90 90 91 def sym_difference(self, *args, **kwargs): 91 return self.get_query _set().sym_difference(*args, **kwargs)92 return self.get_queryset().sym_difference(*args, **kwargs) 92 93 93 94 def transform(self, *args, **kwargs): 94 return self.get_query _set().transform(*args, **kwargs)95 return self.get_queryset().transform(*args, **kwargs) 95 96 96 97 def translate(self, *args, **kwargs): 97 return self.get_query _set().translate(*args, **kwargs)98 return self.get_queryset().translate(*args, **kwargs) 98 99 99 100 def union(self, *args, **kwargs): 100 return self.get_query _set().union(*args, **kwargs)101 return self.get_queryset().union(*args, **kwargs) 101 102 102 103 def unionagg(self, *args, **kwargs): 103 return self.get_query _set().unionagg(*args, **kwargs)104 return self.get_queryset().unionagg(*args, **kwargs) -
django/contrib/sites/managers.py
diff --git a/django/contrib/sites/managers.py b/django/contrib/sites/managers.py index 3df485a..449e081 100644
a b from django.conf import settings 2 2 from django.db import models 3 3 from django.db.models.fields import FieldDoesNotExist 4 4 5 5 6 class CurrentSiteManager(models.Manager): 6 7 "Use this to limit objects to those associated with the current site." 7 8 def __init__(self, field_name=None): … … class CurrentSiteManager(models.Manager): 35 36 (self.__class__.__name__, self.__field_name, self.model._meta.object_name)) 36 37 self.__is_validated = True 37 38 38 def get_query _set(self):39 def get_queryset(self): 39 40 if not self.__is_validated: 40 41 self._validate_field_name() 41 return super(CurrentSiteManager, self).get_query _set().filter(**{self.__field_name + '__id__exact': settings.SITE_ID})42 return super(CurrentSiteManager, self).get_queryset().filter(**{self.__field_name + '__id__exact': settings.SITE_ID}) -
django/db/models/fields/related.py
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index bd2e288..7f2e81c 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 DeprecatedGetQuerySet 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.model_name 226 228 227 229 228 class SingleRelatedObjectDescriptor( object):230 class SingleRelatedObjectDescriptor(six.with_metaclass(DeprecatedGetQuerySet)): 229 231 # This class provides the functionality that makes the related-object 230 232 # managers available as attributes on a model class, for fields that have 231 233 # a single "remote" value, on the class pointed to by a related field. … … class SingleRelatedObjectDescriptor(object): 238 240 def is_cached(self, instance): 239 241 return hasattr(instance, self.cache_name) 240 242 241 def get_query _set(self, **db_hints):243 def get_queryset(self, **db_hints): 242 244 db = router.db_for_read(self.related.model, **db_hints) 243 245 return self.related.model._base_manager.using(db) 244 246 … … class SingleRelatedObjectDescriptor(object): 247 249 instance_attr = lambda obj: obj._get_pk_val() 248 250 instances_dict = dict((instance_attr(inst), inst) for inst in instances) 249 251 params = {'%s__pk__in' % self.related.field.name: list(instances_dict)} 250 qs = self.get_query _set(instance=instances[0]).filter(**params)252 qs = self.get_queryset(instance=instances[0]).filter(**params) 251 253 # Since we're going to assign directly in the cache, 252 254 # we must manage the reverse relation cache manually. 253 255 rel_obj_cache_name = self.related.field.get_cache_name() … … class SingleRelatedObjectDescriptor(object): 268 270 else: 269 271 params = {'%s__pk' % self.related.field.name: related_pk} 270 272 try: 271 rel_obj = self.get_query _set(instance=instance).get(**params)273 rel_obj = self.get_queryset(instance=instance).get(**params) 272 274 except self.related.model.DoesNotExist: 273 275 rel_obj = None 274 276 else: … … class SingleRelatedObjectDescriptor(object): 321 323 setattr(value, self.related.field.get_cache_name(), instance) 322 324 323 325 324 class ReverseSingleRelatedObjectDescriptor( object):326 class ReverseSingleRelatedObjectDescriptor(six.with_metaclass(DeprecatedGetQuerySet)): 325 327 # This class provides the functionality that makes the related-object 326 328 # managers available as attributes on a model class, for fields that have 327 329 # a single "remote" value, on the class that defines the related field. … … class ReverseSingleRelatedObjectDescriptor(object): 334 336 def is_cached(self, instance): 335 337 return hasattr(instance, self.cache_name) 336 338 337 def get_query _set(self, **db_hints):339 def get_queryset(self, **db_hints): 338 340 db = router.db_for_read(self.field.rel.to, **db_hints) 339 341 rel_mgr = self.field.rel.to._default_manager 340 342 # If the related manager indicates that it should be used for … … class ReverseSingleRelatedObjectDescriptor(object): 353 355 params = {'%s__pk__in' % self.field.rel.field_name: list(instances_dict)} 354 356 else: 355 357 params = {'%s__in' % self.field.rel.field_name: list(instances_dict)} 356 qs = self.get_query _set(instance=instances[0]).filter(**params)358 qs = self.get_queryset(instance=instances[0]).filter(**params) 357 359 # Since we're going to assign directly in the cache, 358 360 # we must manage the reverse relation cache manually. 359 361 if not self.field.rel.multiple: … … class ReverseSingleRelatedObjectDescriptor(object): 378 380 params = {'%s__%s' % (self.field.rel.field_name, other_field.rel.field_name): val} 379 381 else: 380 382 params = {'%s__exact' % self.field.rel.field_name: val} 381 qs = self.get_query _set(instance=instance)383 qs = self.get_queryset(instance=instance) 382 384 # Assuming the database enforces foreign keys, this won't fail. 383 385 rel_obj = qs.get(**params) 384 386 if not self.field.rel.multiple: … … class ForeignRelatedObjectsDescriptor(object): 490 492 } 491 493 self.model = rel_model 492 494 493 def get_query _set(self):495 def get_queryset(self): 494 496 try: 495 497 return self.instance._prefetched_objects_cache[rel_field.related_query_name()] 496 498 except (AttributeError, KeyError): 497 499 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)500 qs = super(RelatedManager, self).get_queryset().using(db).filter(**self.core_filters) 499 501 if getattr(self.instance, attname) is None: 500 502 return qs.none() 501 503 qs._known_related_objects = {rel_field: {self.instance.pk: self.instance}} … … class ForeignRelatedObjectsDescriptor(object): 507 509 instances_dict = dict((instance_attr(inst), inst) for inst in instances) 508 510 db = self._db or router.db_for_read(self.model, instance=instances[0]) 509 511 query = {'%s__%s__in' % (rel_field.name, attname): list(instances_dict)} 510 qs = super(RelatedManager, self).get_query _set().using(db).filter(**query)512 qs = super(RelatedManager, self).get_queryset().using(db).filter(**query) 511 513 # Since we just bypassed this class' get_query_set(), we must manage 512 514 # the reverse relation manually. 513 515 for rel_obj in qs: … … def create_many_related_manager(superclass, rel): 602 604 else: 603 605 return obj.pk 604 606 605 def get_query _set(self):607 def get_queryset(self): 606 608 try: 607 609 return self.instance._prefetched_objects_cache[self.prefetch_cache_name] 608 610 except (AttributeError, KeyError): 609 611 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)612 return super(ManyRelatedManager, self).get_queryset().using(db)._next_is_sticky().filter(**self.core_filters) 611 613 612 614 def get_prefetch_query_set(self, instances): 613 615 instance = instances[0] … … def create_many_related_manager(superclass, rel): 615 617 db = self._db or router.db_for_read(instance.__class__, instance=instance) 616 618 query = {'%s__pk__in' % self.query_field_name: 617 619 set(obj._get_pk_val() for obj in instances)} 618 qs = super(ManyRelatedManager, self).get_query _set().using(db)._next_is_sticky().filter(**query)620 qs = super(ManyRelatedManager, self).get_queryset().using(db)._next_is_sticky().filter(**query) 619 621 620 622 # M2M: need to annotate the query in order to get the primary model 621 623 # that the secondary model was actually related to. We know that -
django/db/models/manager.py
diff --git a/django/db/models/manager.py b/django/db/models/manager.py index cee2131..bc1724c 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 import six 7 from django.utils.deprecation import DeprecatedGetQuerySet 6 8 7 9 8 10 def ensure_default_manager(sender, **kwargs): … … def ensure_default_manager(sender, **kwargs): 47 49 signals.class_prepared.connect(ensure_default_manager) 48 50 49 51 50 class Manager( object):52 class Manager(six.with_metaclass(DeprecatedGetQuerySet)): 51 53 # Tracks each time a Manager instance is created. Used to retain order. 52 54 creation_counter = 0 53 55 … … class Manager(object): 112 114 # PROXIES TO QUERYSET # 113 115 ####################### 114 116 115 def get_query _set(self):117 def get_queryset(self): 116 118 """Returns a new QuerySet object. Subclasses can override this method 117 119 to easily customize the behavior of the Manager. 118 120 """ 119 121 return QuerySet(self.model, using=self._db) 120 122 121 123 def none(self): 122 return self.get_query _set().none()124 return self.get_queryset().none() 123 125 124 126 def all(self): 125 return self.get_query _set()127 return self.get_queryset() 126 128 127 129 def count(self): 128 return self.get_query _set().count()130 return self.get_queryset().count() 129 131 130 132 def dates(self, *args, **kwargs): 131 return self.get_query _set().dates(*args, **kwargs)133 return self.get_queryset().dates(*args, **kwargs) 132 134 133 135 def distinct(self, *args, **kwargs): 134 return self.get_query _set().distinct(*args, **kwargs)136 return self.get_queryset().distinct(*args, **kwargs) 135 137 136 138 def extra(self, *args, **kwargs): 137 return self.get_query _set().extra(*args, **kwargs)139 return self.get_queryset().extra(*args, **kwargs) 138 140 139 141 def get(self, *args, **kwargs): 140 return self.get_query _set().get(*args, **kwargs)142 return self.get_queryset().get(*args, **kwargs) 141 143 142 144 def get_or_create(self, **kwargs): 143 return self.get_query _set().get_or_create(**kwargs)145 return self.get_queryset().get_or_create(**kwargs) 144 146 145 147 def create(self, **kwargs): 146 return self.get_query _set().create(**kwargs)148 return self.get_queryset().create(**kwargs) 147 149 148 150 def bulk_create(self, *args, **kwargs): 149 return self.get_query _set().bulk_create(*args, **kwargs)151 return self.get_queryset().bulk_create(*args, **kwargs) 150 152 151 153 def filter(self, *args, **kwargs): 152 return self.get_query _set().filter(*args, **kwargs)154 return self.get_queryset().filter(*args, **kwargs) 153 155 154 156 def aggregate(self, *args, **kwargs): 155 return self.get_query _set().aggregate(*args, **kwargs)157 return self.get_queryset().aggregate(*args, **kwargs) 156 158 157 159 def annotate(self, *args, **kwargs): 158 return self.get_query _set().annotate(*args, **kwargs)160 return self.get_queryset().annotate(*args, **kwargs) 159 161 160 162 def complex_filter(self, *args, **kwargs): 161 return self.get_query _set().complex_filter(*args, **kwargs)163 return self.get_queryset().complex_filter(*args, **kwargs) 162 164 163 165 def exclude(self, *args, **kwargs): 164 return self.get_query _set().exclude(*args, **kwargs)166 return self.get_queryset().exclude(*args, **kwargs) 165 167 166 168 def in_bulk(self, *args, **kwargs): 167 return self.get_query _set().in_bulk(*args, **kwargs)169 return self.get_queryset().in_bulk(*args, **kwargs) 168 170 169 171 def iterator(self, *args, **kwargs): 170 return self.get_query _set().iterator(*args, **kwargs)172 return self.get_queryset().iterator(*args, **kwargs) 171 173 172 174 def earliest(self, *args, **kwargs): 173 return self.get_query _set().earliest(*args, **kwargs)175 return self.get_queryset().earliest(*args, **kwargs) 174 176 175 177 def latest(self, *args, **kwargs): 176 return self.get_query _set().latest(*args, **kwargs)178 return self.get_queryset().latest(*args, **kwargs) 177 179 178 180 def order_by(self, *args, **kwargs): 179 return self.get_query _set().order_by(*args, **kwargs)181 return self.get_queryset().order_by(*args, **kwargs) 180 182 181 183 def select_for_update(self, *args, **kwargs): 182 return self.get_query _set().select_for_update(*args, **kwargs)184 return self.get_queryset().select_for_update(*args, **kwargs) 183 185 184 186 def select_related(self, *args, **kwargs): 185 return self.get_query _set().select_related(*args, **kwargs)187 return self.get_queryset().select_related(*args, **kwargs) 186 188 187 189 def prefetch_related(self, *args, **kwargs): 188 return self.get_query _set().prefetch_related(*args, **kwargs)190 return self.get_queryset().prefetch_related(*args, **kwargs) 189 191 190 192 def values(self, *args, **kwargs): 191 return self.get_query _set().values(*args, **kwargs)193 return self.get_queryset().values(*args, **kwargs) 192 194 193 195 def values_list(self, *args, **kwargs): 194 return self.get_query _set().values_list(*args, **kwargs)196 return self.get_queryset().values_list(*args, **kwargs) 195 197 196 198 def update(self, *args, **kwargs): 197 return self.get_query _set().update(*args, **kwargs)199 return self.get_queryset().update(*args, **kwargs) 198 200 199 201 def reverse(self, *args, **kwargs): 200 return self.get_query _set().reverse(*args, **kwargs)202 return self.get_queryset().reverse(*args, **kwargs) 201 203 202 204 def defer(self, *args, **kwargs): 203 return self.get_query _set().defer(*args, **kwargs)205 return self.get_queryset().defer(*args, **kwargs) 204 206 205 207 def only(self, *args, **kwargs): 206 return self.get_query _set().only(*args, **kwargs)208 return self.get_queryset().only(*args, **kwargs) 207 209 208 210 def using(self, *args, **kwargs): 209 return self.get_query _set().using(*args, **kwargs)211 return self.get_queryset().using(*args, **kwargs) 210 212 211 213 def exists(self, *args, **kwargs): 212 return self.get_query _set().exists(*args, **kwargs)214 return self.get_queryset().exists(*args, **kwargs) 213 215 214 216 def _insert(self, objs, fields, **kwargs): 215 217 return insert_query(self.model, objs, fields, **kwargs) 216 218 217 219 def _update(self, values, **kwargs): 218 return self.get_query _set()._update(values, **kwargs)220 return self.get_queryset()._update(values, **kwargs) 219 221 220 222 def raw(self, raw_query, params=None, *args, **kwargs): 221 223 return RawQuerySet(raw_query=raw_query, model=self.model, params=params, using=self._db, *args, **kwargs) … … class EmptyManager(Manager): 262 264 super(EmptyManager, self).__init__() 263 265 self.model = model 264 266 265 def get_query _set(self):266 return super(EmptyManager, self).get_query _set().none()267 def get_queryset(self): 268 return super(EmptyManager, self).get_queryset().none() -
django/forms/models.py
diff --git a/django/forms/models.py b/django/forms/models.py index e2d739f..3948780 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 if form._meta.widgets: 682 682 widget = form._meta.widgets.get(self._pk_field.name, HiddenInput) -
new file django/utils/deprecation.py
diff --git a/django/utils/deprecation.py b/django/utils/deprecation.py new file mode 100644 index 0000000..eac306f
- + 1 from __future__ import unicode_literals 2 import warnings 3 4 from django.core.exceptions import ImproperlyConfigured 5 from django.utils.unittest.compatibility import wraps 6 7 8 def get_query_set_complain(name, get_query_set): 9 @wraps(get_query_set) 10 def complain(*args, **kwargs): 11 warnings.warn( 12 "`%s.get_query_set` is deprecated, use " 13 "`get_queryset` instead." % name, 14 PendingDeprecationWarning, 2) 15 return get_query_set(*args, **kwargs) 16 return complain 17 18 19 class DeprecatedGetQuerySet(type): 20 """ 21 Handles the deprecation paths of `get_queryset` in favor of `get_query_set`. 22 23 It does the following: 24 1) Issue a warning on class creation if `get_query_set` is defined. 25 2) Raise an `ImproperlyConfigured` error if both `get_queryset` and 26 `get_query_set` are defined. 27 3) Define a `get_queryset` method if not present. 28 4) Define or wrap the existing `get_query_set` to complain when called. 29 30 See #15363 for more details. 31 """ 32 def __new__(cls, name, bases, attrs): 33 get_query_set = attrs.get('get_query_set') 34 get_queryset = attrs.get('get_queryset') 35 if get_query_set: 36 if get_queryset: 37 raise ImproperlyConfigured( 38 "'Class `%s` should either define `get_queryset` or " 39 "`get_query_set` not both.'" % name) 40 else: 41 attrs['get_queryset'] = get_query_set 42 warnings.warn( 43 "`%s.get_query_set` method should be " 44 "renamed `get_queryset`." % name, 45 PendingDeprecationWarning, 2) 46 get_query_set = get_query_set_complain(name, get_query_set) 47 elif get_queryset: 48 get_query_set = get_query_set_complain(name, get_queryset) 49 if get_query_set: 50 attrs['get_query_set'] = get_query_set 51 return type.__new__(cls, name, bases, attrs) 52 No newline at end of file -
tests/modeltests/custom_managers/models.py
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): -
tests/modeltests/fixtures/models.py
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() -
tests/modeltests/generic_relations/models.py
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() -
tests/modeltests/get_object_or_404/models.py
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): -
tests/modeltests/prefetch_related/models.py
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 -
tests/modeltests/proxy_models/models.py
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): -
tests/regressiontests/admin_changelist/models.py
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 """ -
tests/regressiontests/admin_changelist/tests.py
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't42 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) -
tests/regressiontests/admin_filters/tests.py
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] -
tests/regressiontests/admin_views/admin.py
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 -
tests/regressiontests/admin_widgets/models.py
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): -
tests/regressiontests/custom_managers_regress/models.py
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): -
new file tests/regressiontests/deprecation/tests.py
diff --git a/tests/regressiontests/deprecation/__init__.py b/tests/regressiontests/deprecation/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/deprecation/models.py b/tests/regressiontests/deprecation/models.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/deprecation/tests.py b/tests/regressiontests/deprecation/tests.py new file mode 100644 index 0000000..0ff402c
- + 1 from __future__ import unicode_literals 2 import warnings 3 4 from django.test.testcases import SimpleTestCase 5 from django.utils import six 6 from django.utils.deprecation import DeprecatedGetQuerySet 7 from django.core.exceptions import ImproperlyConfigured 8 9 10 class DeprecatedGetQuerySetTest(SimpleTestCase): 11 """ 12 Tests the `DeprecatedGetQuerySet` type introduced to rename `get_query_set` 13 to `get_queryset` across code base following #15363. 14 """ 15 def test_class_definition_warnings(self): 16 """ 17 Ensure a warning is raised upon class definition to suggest renaming 18 the faulty method. 19 """ 20 with warnings.catch_warnings(record=True) as recorded: 21 warnings.simplefilter('always') 22 class Manager(six.with_metaclass(DeprecatedGetQuerySet)): 23 def get_query_set(self): 24 pass 25 self.assertEqual(len(recorded), 1) 26 msg = str(recorded[0].message) 27 self.assertEqual(msg, 28 '`Manager.get_query_set` method should be renamed `get_queryset`.') 29 30 def test_get_queryset_defined(self): 31 """ 32 Ensure `get_query_set` complains and not `get_queryset` when only 33 `get_queryset` is defined. 34 """ 35 with warnings.catch_warnings(record=True) as recorded: 36 warnings.simplefilter('ignore') 37 class Manager(six.with_metaclass(DeprecatedGetQuerySet)): 38 def get_queryset(self): 39 pass 40 warnings.simplefilter('always') 41 manager = Manager() 42 manager.get_queryset() 43 self.assertEqual(len(recorded), 0) 44 manager.get_query_set() 45 self.assertEqual(len(recorded), 1) 46 msg = str(recorded.pop().message) 47 self.assertEqual(msg, 48 '`Manager.get_query_set` is deprecated, use `get_queryset` instead.') 49 50 def test_get_query_set_defined(self): 51 """ 52 Ensure `get_query_set` complains and not `get_queryset` when only 53 `get_query_set` is defined. 54 """ 55 with warnings.catch_warnings(record=True) as recorded: 56 warnings.simplefilter('ignore') 57 class Manager(six.with_metaclass(DeprecatedGetQuerySet)): 58 def get_query_set(self): 59 pass 60 warnings.simplefilter('always') 61 manager = Manager() 62 manager.get_queryset() 63 self.assertEqual(len(recorded), 0) 64 manager.get_query_set() 65 self.assertEqual(len(recorded), 1) 66 msg = str(recorded.pop().message) 67 self.assertEqual(msg, 68 '`Manager.get_query_set` is deprecated, use `get_queryset` instead.') 69 70 def test_deprecated_subclass_renamed(self): 71 """ 72 Ensure the correct warnings are raised when a class that didn't rename 73 `get_query_set` subclass one that did. 74 """ 75 with warnings.catch_warnings(record=True) as recorded: 76 warnings.simplefilter('ignore') 77 class Renamed(six.with_metaclass(DeprecatedGetQuerySet)): 78 def get_queryset(self): 79 pass 80 class Deprecated(Renamed): 81 def get_query_set(self): 82 super(Deprecated, self).get_query_set() 83 warnings.simplefilter('always') 84 deprecated = Deprecated() 85 deprecated.get_queryset() 86 self.assertEqual(len(recorded), 1) 87 msg = str(recorded.pop().message) 88 self.assertEqual(msg, 89 '`Renamed.get_query_set` is deprecated, use `get_queryset` instead.') 90 deprecated.get_query_set() 91 self.assertEqual(len(recorded), 2) 92 msgs = [str(warning.message) for warning in recorded] 93 self.assertEqual(msgs, [ 94 '`Deprecated.get_query_set` is deprecated, use `get_queryset` instead.', 95 '`Renamed.get_query_set` is deprecated, use `get_queryset` instead.']) 96 97 def test_renamed_subclass_deprecated(self): 98 """ 99 Ensure the correct warnings are raised when a class that renamed 100 `get_query_set` subclass one that didn't. 101 """ 102 with warnings.catch_warnings(record=True) as recorded: 103 warnings.simplefilter('ignore') 104 class Deprecated(six.with_metaclass(DeprecatedGetQuerySet)): 105 def get_query_set(self): 106 pass 107 class Renamed(Deprecated): 108 def get_queryset(self): 109 super(Renamed, self).get_queryset() 110 warnings.simplefilter('always') 111 renamed = Renamed() 112 renamed.get_queryset() 113 self.assertEqual(len(recorded), 0) 114 renamed.get_query_set() 115 self.assertEqual(len(recorded), 1) 116 msg = str(recorded.pop().message) 117 self.assertEqual(msg, 118 '`Renamed.get_query_set` is deprecated, use `get_queryset` instead.') 119 120 def test_improperly_configured(self): 121 """ 122 Ensure a significant `ImproperlyConfigured` error is raised when 123 both `get_queryset` and `get_query_set` are defined. 124 """ 125 msg = 'Class `Manager` should either define `get_queryset` or `get_query_set` not both.' 126 with self.assertRaisesMessage(ImproperlyConfigured, msg): 127 class Manager(six.with_metaclass(DeprecatedGetQuerySet)): 128 def get_queryset(self): 129 pass 130 def get_query_set(self): 131 pass 132 No newline at end of file -
tests/regressiontests/managers_regress/models.py
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): -
tests/regressiontests/modeladmin/tests.py
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): -
tests/regressiontests/queries/models.py
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) -
tests/regressiontests/reverse_single_related/models.py
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()