Ticket #15363: ticket-15363-deprecated-metaclass.diff

File ticket-15363-deprecated-metaclass.diff, 59.3 KB (added by Simon Charette, 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)):  
    222222        Returns a QuerySet of all model instances that can be edited by the
    223223        admin site. This is used by changelist_view.
    224224        """
    225         qs = self.model._default_manager.get_query_set()
     225        qs = self.model._default_manager.get_queryset()
    226226        # TODO: this should be handled by some parameter to the ChangeList.
    227227        ordering = self.get_ordering(request)
    228228        if ordering:
    class ModelAdmin(BaseModelAdmin):  
    11871187        if (actions and request.method == 'POST' and
    11881188                'index' in request.POST and '_save' not in request.POST):
    11891189            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))
    11911191                if response:
    11921192                    return response
    11931193                else:
    class ModelAdmin(BaseModelAdmin):  
    12031203                helpers.ACTION_CHECKBOX_NAME in request.POST and
    12041204                'index' not in request.POST and '_save' not in request.POST):
    12051205            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))
    12071207                if response:
    12081208                    return response
    12091209                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  
    66from django.core.urlresolvers import reverse
    77from django.db import models
    88from django.db.models.fields import FieldDoesNotExist
     9from django.utils import six
    910from django.utils.datastructures import SortedDict
     11from django.utils.deprecation import DeprecatedGetQuerySet
    1012from django.utils.encoding import force_str, force_text
    1113from django.utils.translation import ugettext, ugettext_lazy
    1214from django.utils.http import urlencode
    IGNORED_PARAMS = (  
    3335EMPTY_CHANGELIST_VALUE = ugettext_lazy('(None)')
    3436
    3537
    36 class ChangeList(object):
     38class ChangeList(six.with_metaclass(DeprecatedGetQuerySet)):
    3739    def __init__(self, request, model, list_display, list_display_links,
    3840            list_filter, date_hierarchy, search_fields, list_select_related,
    3941            list_per_page, list_max_show_all, list_editable, model_admin):
    class ChangeList(object):  
    7072        else:
    7173            self.list_editable = list_editable
    7274        self.query = request.GET.get(SEARCH_VAR, '')
    73         self.query_set = self.get_query_set(request)
     75        self.query_set = self.get_queryset(request)
    7476        self.get_results(request)
    7577        if self.is_popup:
    7678            title = ugettext('Select %s')
    class ChangeList(object):  
    297299                ordering_fields[idx] = 'desc' if pfx == '-' else 'asc'
    298300        return ordering_fields
    299301
    300     def get_query_set(self, request):
     302    def get_queryset(self, request):
    301303        # First, we collect all the declared list filters.
    302304        (self.filter_specs, self.has_filters, remaining_lookup_params,
    303305         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):  
    88        """
    99        QuerySet for all comments currently in the moderation queue.
    1010        """
    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)
    1212
    1313    def for_model(self, model):
    1414        """
    class CommentManager(models.Manager):  
    1616        a class).
    1717        """
    1818        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)
    2020        if isinstance(model, models.Model):
    2121            qs = qs.filter(object_pk=force_text(model._get_pk_val()))
    2222        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  
    33from django.conf import settings
    44from django.contrib.contenttypes.models import ContentType
    55from django.contrib import comments
     6from django.utils import six
     7from django.utils.deprecation import DeprecatedGetQuerySet
    68from django.utils.encoding import smart_text
    79
    810register = template.Library()
    911
    10 class BaseCommentNode(template.Node):
     12
     13class BaseCommentNode(six.with_metaclass(DeprecatedGetQuerySet, template.Node)):
    1114    """
    1215    Base helper class (abstract) for handling the get_comment_* template tags.
    1316    Looks a bit strange, but the subclasses below should make this a bit more
    class BaseCommentNode(template.Node):  
    6467        self.comment = comment
    6568
    6669    def render(self, context):
    67         qs = self.get_query_set(context)
     70        qs = self.get_queryset(context)
    6871        context[self.as_varname] = self.get_context_value_from_queryset(context, qs)
    6972        return ''
    7073
    71     def get_query_set(self, context):
     74    def get_queryset(self, context):
    7275        ctype, object_pk = self.get_target_ctype_pk(context)
    7376        if not object_pk:
    7477            return self.comment_model.objects.none()
    class RenderCommentListNode(CommentListNode):  
    205208                "comments/%s/list.html" % ctype.app_label,
    206209                "comments/list.html"
    207210            ]
    208             qs = self.get_query_set(context)
     211            qs = self.get_queryset(context)
    209212            context.push()
    210213            liststr = render_to_string(template_search_list, {
    211214                "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):  
    316316                '%s__exact' % object_id_field_name: instance._get_pk_val(),
    317317            }
    318318
    319         def get_query_set(self):
     319        def get_queryset(self):
    320320            try:
    321321                return self.instance._prefetched_objects_cache[self.prefetch_cache_name]
    322322            except (AttributeError, KeyError):
    323323                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)
    325325
    326326        def get_prefetch_query_set(self, instances):
    327327            db = self._db or router.db_for_read(self.model, instance=instances[0])
    def create_generic_related_manager(superclass):  
    330330                '%s__in' % self.object_id_field_name:
    331331                    set(obj._get_pk_val() for obj in instances)
    332332                }
    333             qs = super(GenericRelatedObjectManager, self).get_query_set().using(db).filter(**query)
     333            qs = super(GenericRelatedObjectManager, self).get_queryset().using(db).filter(**query)
    334334            # We (possibly) need to convert object IDs to the type of the
    335335            # instances' PK in order to match up instances:
    336336            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  
    11from django.db.models.manager import Manager
    22from django.contrib.gis.db.models.query import GeoQuerySet
    33
     4
    45class GeoManager(Manager):
    56    "Overrides Manager to return Geographic QuerySets."
    67
    class GeoManager(Manager):  
    910    # properly.
    1011    use_for_related_fields = True
    1112
    12     def get_query_set(self):
     13    def get_queryset(self):
    1314        return GeoQuerySet(self.model, using=self._db)
    1415
    1516    def area(self, *args, **kwargs):
    16         return self.get_query_set().area(*args, **kwargs)
     17        return self.get_queryset().area(*args, **kwargs)
    1718
    1819    def centroid(self, *args, **kwargs):
    19         return self.get_query_set().centroid(*args, **kwargs)
     20        return self.get_queryset().centroid(*args, **kwargs)
    2021
    2122    def collect(self, *args, **kwargs):
    22         return self.get_query_set().collect(*args, **kwargs)
     23        return self.get_queryset().collect(*args, **kwargs)
    2324
    2425    def difference(self, *args, **kwargs):
    25         return self.get_query_set().difference(*args, **kwargs)
     26        return self.get_queryset().difference(*args, **kwargs)
    2627
    2728    def distance(self, *args, **kwargs):
    28         return self.get_query_set().distance(*args, **kwargs)
     29        return self.get_queryset().distance(*args, **kwargs)
    2930
    3031    def envelope(self, *args, **kwargs):
    31         return self.get_query_set().envelope(*args, **kwargs)
     32        return self.get_queryset().envelope(*args, **kwargs)
    3233
    3334    def extent(self, *args, **kwargs):
    34         return self.get_query_set().extent(*args, **kwargs)
     35        return self.get_queryset().extent(*args, **kwargs)
    3536
    3637    def extent3d(self, *args, **kwargs):
    37         return self.get_query_set().extent3d(*args, **kwargs)
     38        return self.get_queryset().extent3d(*args, **kwargs)
    3839
    3940    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)
    4142
    4243    def geohash(self, *args, **kwargs):
    43         return self.get_query_set().geohash(*args, **kwargs)
     44        return self.get_queryset().geohash(*args, **kwargs)
    4445
    4546    def geojson(self, *args, **kwargs):
    46         return self.get_query_set().geojson(*args, **kwargs)
     47        return self.get_queryset().geojson(*args, **kwargs)
    4748
    4849    def gml(self, *args, **kwargs):
    49         return self.get_query_set().gml(*args, **kwargs)
     50        return self.get_queryset().gml(*args, **kwargs)
    5051
    5152    def intersection(self, *args, **kwargs):
    52         return self.get_query_set().intersection(*args, **kwargs)
     53        return self.get_queryset().intersection(*args, **kwargs)
    5354
    5455    def kml(self, *args, **kwargs):
    55         return self.get_query_set().kml(*args, **kwargs)
     56        return self.get_queryset().kml(*args, **kwargs)
    5657
    5758    def length(self, *args, **kwargs):
    58         return self.get_query_set().length(*args, **kwargs)
     59        return self.get_queryset().length(*args, **kwargs)
    5960
    6061    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)
    6263
    6364    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)
    6566
    6667    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)
    6869
    6970    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)
    7172
    7273    def perimeter(self, *args, **kwargs):
    73         return self.get_query_set().perimeter(*args, **kwargs)
     74        return self.get_queryset().perimeter(*args, **kwargs)
    7475
    7576    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)
    7778
    7879    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)
    8081
    8182    def scale(self, *args, **kwargs):
    82         return self.get_query_set().scale(*args, **kwargs)
     83        return self.get_queryset().scale(*args, **kwargs)
    8384
    8485    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)
    8687
    8788    def svg(self, *args, **kwargs):
    88         return self.get_query_set().svg(*args, **kwargs)
     89        return self.get_queryset().svg(*args, **kwargs)
    8990
    9091    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)
    9293
    9394    def transform(self, *args, **kwargs):
    94         return self.get_query_set().transform(*args, **kwargs)
     95        return self.get_queryset().transform(*args, **kwargs)
    9596
    9697    def translate(self, *args, **kwargs):
    97         return self.get_query_set().translate(*args, **kwargs)
     98        return self.get_queryset().translate(*args, **kwargs)
    9899
    99100    def union(self, *args, **kwargs):
    100         return self.get_query_set().union(*args, **kwargs)
     101        return self.get_queryset().union(*args, **kwargs)
    101102
    102103    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  
    22from django.db import models
    33from django.db.models.fields import FieldDoesNotExist
    44
     5
    56class CurrentSiteManager(models.Manager):
    67    "Use this to limit objects to those associated with the current site."
    78    def __init__(self, field_name=None):
    class CurrentSiteManager(models.Manager):  
    3536                    (self.__class__.__name__, self.__field_name, self.model._meta.object_name))
    3637        self.__is_validated = True
    3738   
    38     def get_query_set(self):
     39    def get_queryset(self):
    3940        if not self.__is_validated:
    4041            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  
    11from operator import attrgetter
    22
     3from django import forms
     4from django.core import exceptions
    35from django.db import connection, router
    46from django.db.backends import util
    57from django.db.models import signals, get_model
    from django.db.models.query_utils import QueryWrapper  
    1113from django.db.models.deletion import CASCADE
    1214from django.utils.encoding import smart_text
    1315from django.utils import six
     16from django.utils.deprecation import DeprecatedGetQuerySet
    1417from django.utils.translation import ugettext_lazy as _, string_concat
    1518from django.utils.functional import curry, cached_property
    16 from django.core import exceptions
    17 from django import forms
     19
    1820
    1921RECURSIVE_RELATIONSHIP_CONSTANT = 'self'
    2022
    class RelatedField(object):  
    225227        return self.rel.related_name or self.opts.model_name
    226228
    227229
    228 class SingleRelatedObjectDescriptor(object):
     230class SingleRelatedObjectDescriptor(six.with_metaclass(DeprecatedGetQuerySet)):
    229231    # This class provides the functionality that makes the related-object
    230232    # managers available as attributes on a model class, for fields that have
    231233    # a single "remote" value, on the class pointed to by a related field.
    class SingleRelatedObjectDescriptor(object):  
    238240    def is_cached(self, instance):
    239241        return hasattr(instance, self.cache_name)
    240242
    241     def get_query_set(self, **db_hints):
     243    def get_queryset(self, **db_hints):
    242244        db = router.db_for_read(self.related.model, **db_hints)
    243245        return self.related.model._base_manager.using(db)
    244246
    class SingleRelatedObjectDescriptor(object):  
    247249        instance_attr = lambda obj: obj._get_pk_val()
    248250        instances_dict = dict((instance_attr(inst), inst) for inst in instances)
    249251        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)
    251253        # Since we're going to assign directly in the cache,
    252254        # we must manage the reverse relation cache manually.
    253255        rel_obj_cache_name = self.related.field.get_cache_name()
    class SingleRelatedObjectDescriptor(object):  
    268270            else:
    269271                params = {'%s__pk' % self.related.field.name: related_pk}
    270272                try:
    271                     rel_obj = self.get_query_set(instance=instance).get(**params)
     273                    rel_obj = self.get_queryset(instance=instance).get(**params)
    272274                except self.related.model.DoesNotExist:
    273275                    rel_obj = None
    274276                else:
    class SingleRelatedObjectDescriptor(object):  
    321323        setattr(value, self.related.field.get_cache_name(), instance)
    322324
    323325
    324 class ReverseSingleRelatedObjectDescriptor(object):
     326class ReverseSingleRelatedObjectDescriptor(six.with_metaclass(DeprecatedGetQuerySet)):
    325327    # This class provides the functionality that makes the related-object
    326328    # managers available as attributes on a model class, for fields that have
    327329    # a single "remote" value, on the class that defines the related field.
    class ReverseSingleRelatedObjectDescriptor(object):  
    334336    def is_cached(self, instance):
    335337        return hasattr(instance, self.cache_name)
    336338
    337     def get_query_set(self, **db_hints):
     339    def get_queryset(self, **db_hints):
    338340        db = router.db_for_read(self.field.rel.to, **db_hints)
    339341        rel_mgr = self.field.rel.to._default_manager
    340342        # If the related manager indicates that it should be used for
    class ReverseSingleRelatedObjectDescriptor(object):  
    353355            params = {'%s__pk__in' % self.field.rel.field_name: list(instances_dict)}
    354356        else:
    355357            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)
    357359        # Since we're going to assign directly in the cache,
    358360        # we must manage the reverse relation cache manually.
    359361        if not self.field.rel.multiple:
    class ReverseSingleRelatedObjectDescriptor(object):  
    378380                    params = {'%s__%s' % (self.field.rel.field_name, other_field.rel.field_name): val}
    379381                else:
    380382                    params = {'%s__exact' % self.field.rel.field_name: val}
    381                 qs = self.get_query_set(instance=instance)
     383                qs = self.get_queryset(instance=instance)
    382384                # Assuming the database enforces foreign keys, this won't fail.
    383385                rel_obj = qs.get(**params)
    384386                if not self.field.rel.multiple:
    class ForeignRelatedObjectsDescriptor(object):  
    490492                }
    491493                self.model = rel_model
    492494
    493             def get_query_set(self):
     495            def get_queryset(self):
    494496                try:
    495497                    return self.instance._prefetched_objects_cache[rel_field.related_query_name()]
    496498                except (AttributeError, KeyError):
    497499                    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)
    499501                    if getattr(self.instance, attname) is None:
    500502                        return qs.none()
    501503                    qs._known_related_objects = {rel_field: {self.instance.pk: self.instance}}
    class ForeignRelatedObjectsDescriptor(object):  
    507509                instances_dict = dict((instance_attr(inst), inst) for inst in instances)
    508510                db = self._db or router.db_for_read(self.model, instance=instances[0])
    509511                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)
    511513                # Since we just bypassed this class' get_query_set(), we must manage
    512514                # the reverse relation manually.
    513515                for rel_obj in qs:
    def create_many_related_manager(superclass, rel):  
    602604            else:
    603605                return obj.pk
    604606
    605         def get_query_set(self):
     607        def get_queryset(self):
    606608            try:
    607609                return self.instance._prefetched_objects_cache[self.prefetch_cache_name]
    608610            except (AttributeError, KeyError):
    609611                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)
    611613
    612614        def get_prefetch_query_set(self, instances):
    613615            instance = instances[0]
    def create_many_related_manager(superclass, rel):  
    615617            db = self._db or router.db_for_read(instance.__class__, instance=instance)
    616618            query = {'%s__pk__in' % self.query_field_name:
    617619                         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)
    619621
    620622            # M2M: need to annotate the query in order to get the primary model
    621623            # 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  
    33from django.db.models.query import QuerySet, insert_query, RawQuerySet
    44from django.db.models import signals
    55from django.db.models.fields import FieldDoesNotExist
     6from django.utils import six
     7from django.utils.deprecation import DeprecatedGetQuerySet
    68
    79
    810def ensure_default_manager(sender, **kwargs):
    def ensure_default_manager(sender, **kwargs):  
    4749signals.class_prepared.connect(ensure_default_manager)
    4850
    4951
    50 class Manager(object):
     52class Manager(six.with_metaclass(DeprecatedGetQuerySet)):
    5153    # Tracks each time a Manager instance is created. Used to retain order.
    5254    creation_counter = 0
    5355
    class Manager(object):  
    112114    # PROXIES TO QUERYSET #
    113115    #######################
    114116
    115     def get_query_set(self):
     117    def get_queryset(self):
    116118        """Returns a new QuerySet object.  Subclasses can override this method
    117119        to easily customize the behavior of the Manager.
    118120        """
    119121        return QuerySet(self.model, using=self._db)
    120122
    121123    def none(self):
    122         return self.get_query_set().none()
     124        return self.get_queryset().none()
    123125
    124126    def all(self):
    125         return self.get_query_set()
     127        return self.get_queryset()
    126128
    127129    def count(self):
    128         return self.get_query_set().count()
     130        return self.get_queryset().count()
    129131
    130132    def dates(self, *args, **kwargs):
    131         return self.get_query_set().dates(*args, **kwargs)
     133        return self.get_queryset().dates(*args, **kwargs)
    132134
    133135    def distinct(self, *args, **kwargs):
    134         return self.get_query_set().distinct(*args, **kwargs)
     136        return self.get_queryset().distinct(*args, **kwargs)
    135137
    136138    def extra(self, *args, **kwargs):
    137         return self.get_query_set().extra(*args, **kwargs)
     139        return self.get_queryset().extra(*args, **kwargs)
    138140
    139141    def get(self, *args, **kwargs):
    140         return self.get_query_set().get(*args, **kwargs)
     142        return self.get_queryset().get(*args, **kwargs)
    141143
    142144    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)
    144146
    145147    def create(self, **kwargs):
    146         return self.get_query_set().create(**kwargs)
     148        return self.get_queryset().create(**kwargs)
    147149
    148150    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)
    150152
    151153    def filter(self, *args, **kwargs):
    152         return self.get_query_set().filter(*args, **kwargs)
     154        return self.get_queryset().filter(*args, **kwargs)
    153155
    154156    def aggregate(self, *args, **kwargs):
    155         return self.get_query_set().aggregate(*args, **kwargs)
     157        return self.get_queryset().aggregate(*args, **kwargs)
    156158
    157159    def annotate(self, *args, **kwargs):
    158         return self.get_query_set().annotate(*args, **kwargs)
     160        return self.get_queryset().annotate(*args, **kwargs)
    159161
    160162    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)
    162164
    163165    def exclude(self, *args, **kwargs):
    164         return self.get_query_set().exclude(*args, **kwargs)
     166        return self.get_queryset().exclude(*args, **kwargs)
    165167
    166168    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)
    168170
    169171    def iterator(self, *args, **kwargs):
    170         return self.get_query_set().iterator(*args, **kwargs)
     172        return self.get_queryset().iterator(*args, **kwargs)
    171173
    172174    def earliest(self, *args, **kwargs):
    173         return self.get_query_set().earliest(*args, **kwargs)
     175        return self.get_queryset().earliest(*args, **kwargs)
    174176
    175177    def latest(self, *args, **kwargs):
    176         return self.get_query_set().latest(*args, **kwargs)
     178        return self.get_queryset().latest(*args, **kwargs)
    177179
    178180    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)
    180182
    181183    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)
    183185
    184186    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)
    186188
    187189    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)
    189191
    190192    def values(self, *args, **kwargs):
    191         return self.get_query_set().values(*args, **kwargs)
     193        return self.get_queryset().values(*args, **kwargs)
    192194
    193195    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)
    195197
    196198    def update(self, *args, **kwargs):
    197         return self.get_query_set().update(*args, **kwargs)
     199        return self.get_queryset().update(*args, **kwargs)
    198200
    199201    def reverse(self, *args, **kwargs):
    200         return self.get_query_set().reverse(*args, **kwargs)
     202        return self.get_queryset().reverse(*args, **kwargs)
    201203
    202204    def defer(self, *args, **kwargs):
    203         return self.get_query_set().defer(*args, **kwargs)
     205        return self.get_queryset().defer(*args, **kwargs)
    204206
    205207    def only(self, *args, **kwargs):
    206         return self.get_query_set().only(*args, **kwargs)
     208        return self.get_queryset().only(*args, **kwargs)
    207209
    208210    def using(self, *args, **kwargs):
    209         return self.get_query_set().using(*args, **kwargs)
     211        return self.get_queryset().using(*args, **kwargs)
    210212
    211213    def exists(self, *args, **kwargs):
    212         return self.get_query_set().exists(*args, **kwargs)
     214        return self.get_queryset().exists(*args, **kwargs)
    213215
    214216    def _insert(self, objs, fields, **kwargs):
    215217        return insert_query(self.model, objs, fields, **kwargs)
    216218
    217219    def _update(self, values, **kwargs):
    218         return self.get_query_set()._update(values, **kwargs)
     220        return self.get_queryset()._update(values, **kwargs)
    219221
    220222    def raw(self, raw_query, params=None, *args, **kwargs):
    221223        return RawQuerySet(raw_query=raw_query, model=self.model, params=params, using=self._db, *args, **kwargs)
    class EmptyManager(Manager):  
    262264        super(EmptyManager, self).__init__()
    263265        self.model = model
    264266
    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):  
    479479            if self.queryset is not None:
    480480                qs = self.queryset
    481481            else:
    482                 qs = self.model._default_manager.get_query_set()
     482                qs = self.model._default_manager.get_queryset()
    483483
    484484            # If the queryset isn't already ordered we need to add an
    485485            # artificial ordering here to make sure that all formsets
    class BaseModelFormSet(BaseFormSet):  
    674674                except IndexError:
    675675                    pk_value = None
    676676            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()
    678678            else:
    679                 qs = self.model._default_manager.get_query_set()
     679                qs = self.model._default_manager.get_queryset()
    680680            qs = qs.using(form.instance._state.db)
    681681            if form._meta.widgets:
    682682                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
    - +  
     1from __future__ import unicode_literals
     2import warnings
     3
     4from django.core.exceptions import ImproperlyConfigured
     5from django.utils.unittest.compatibility import wraps
     6
     7
     8def 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
     19class 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):  
    3030    def __str__(self):
    3131        return "%s %s" % (self.first_name, self.last_name)
    3232
    33 # An example of a custom manager that sets get_query_set().
     33# An example of a custom manager that sets get_queryset().
    3434
    3535class 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)
    3838
    3939@python_2_unicode_compatible
    4040class Book(models.Model):
    class Book(models.Model):  
    5050# An example of providing multiple custom managers.
    5151
    5252class 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)
    5555
    5656@python_2_unicode_compatible
    5757class 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):  
    7878        return (self.name,)
    7979
    8080class 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)
    8383
    8484class Spy(Person):
    8585    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):  
    8888        return self.name
    8989
    9090class 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)
    9393
    9494class Gecko(models.Model):
    9595    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):  
    2222        return self.name
    2323
    2424class 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')
    2727
    2828@python_2_unicode_compatible
    2929class 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):  
    8787
    8888
    8989class 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')
    9292
    9393
    9494@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  
    1010# A couple of managers for testing managing overriding in proxy model cases.
    1111
    1212class 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")
    1515
    1616class 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")
    1919
    2020@python_2_unicode_compatible
    2121class 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):  
    7474
    7575
    7676class 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')
    7979
    8080class OrderedObject(models.Model):
    8181    """
  • 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):  
    3939
    4040    def test_select_related_preserved(self):
    4141        """
    42         Regression test for #10348: ChangeList.get_query_set() shouldn't
     42        Regression test for #10348: ChangeList.get_queryset() shouldn't
    4343        overwrite a custom select_related provided by ModelAdmin.queryset().
    4444        """
    4545        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):  
    183183        changelist = self.get_changelist(request, Book, modeladmin)
    184184
    185185        # Make sure the correct queryset is returned
    186         queryset = changelist.get_query_set(request)
     186        queryset = changelist.get_queryset(request)
    187187        self.assertEqual(list(queryset), [self.django_book, self.djangonaut_book])
    188188
    189189        # Make sure the correct choice is selected
    class ListFiltersTests(TestCase):  
    200200        changelist = self.get_changelist(request, Book, modeladmin)
    201201
    202202        # Make sure the correct queryset is returned
    203         queryset = changelist.get_query_set(request)
     203        queryset = changelist.get_queryset(request)
    204204        if (self.today.year, self.today.month) == (self.one_week_ago.year, self.one_week_ago.month):
    205205            # In case one week ago is in the same month.
    206206            self.assertEqual(list(queryset), [self.gipsy_book, self.django_book, self.djangonaut_book])
    class ListFiltersTests(TestCase):  
    221221        changelist = self.get_changelist(request, Book, modeladmin)
    222222
    223223        # Make sure the correct queryset is returned
    224         queryset = changelist.get_query_set(request)
     224        queryset = changelist.get_queryset(request)
    225225        if self.today.year == self.one_week_ago.year:
    226226            # In case one week ago is in the same year.
    227227            self.assertEqual(list(queryset), [self.gipsy_book, self.django_book, self.djangonaut_book])
    class ListFiltersTests(TestCase):  
    242242        changelist = self.get_changelist(request, Book, modeladmin)
    243243
    244244        # Make sure the correct queryset is returned
    245         queryset = changelist.get_query_set(request)
     245        queryset = changelist.get_queryset(request)
    246246        self.assertEqual(list(queryset), [self.gipsy_book, self.django_book, self.djangonaut_book])
    247247
    248248        # Make sure the correct choice is selected
    class ListFiltersTests(TestCase):  
    266266        changelist = self.get_changelist(request, Book, modeladmin)
    267267
    268268        # Make sure the correct queryset is returned
    269         queryset = changelist.get_query_set(request)
     269        queryset = changelist.get_queryset(request)
    270270        self.assertEqual(list(queryset), [self.django_book])
    271271
    272272        # Make sure the last choice is None and is selected
    class ListFiltersTests(TestCase):  
    293293        changelist = self.get_changelist(request, Book, modeladmin)
    294294
    295295        # Make sure the correct queryset is returned
    296         queryset = changelist.get_query_set(request)
     296        queryset = changelist.get_queryset(request)
    297297        self.assertEqual(list(queryset), [self.gipsy_book])
    298298
    299299        # Make sure the last choice is None and is selected
    class ListFiltersTests(TestCase):  
    321321        changelist = self.get_changelist(request, Book, modeladmin)
    322322
    323323        # Make sure the correct queryset is returned
    324         queryset = changelist.get_query_set(request)
     324        queryset = changelist.get_queryset(request)
    325325        self.assertEqual(list(queryset), [self.django_book, self.bio_book, self.djangonaut_book])
    326326
    327327        # Make sure the last choice is None and is selected
    class ListFiltersTests(TestCase):  
    349349        changelist = self.get_changelist(request, User, modeladmin)
    350350
    351351        # Make sure the correct queryset is returned
    352         queryset = changelist.get_query_set(request)
     352        queryset = changelist.get_queryset(request)
    353353        self.assertEqual(list(queryset), [self.lisa])
    354354
    355355        # Make sure the last choice is None and is selected
    class ListFiltersTests(TestCase):  
    374374        changelist = self.get_changelist(request, User, modeladmin)
    375375
    376376        # Make sure the correct queryset is returned
    377         queryset = changelist.get_query_set(request)
     377        queryset = changelist.get_queryset(request)
    378378        self.assertEqual(list(queryset), [self.alfred])
    379379
    380380        # Make sure the last choice is None and is selected
    class ListFiltersTests(TestCase):  
    410410        changelist = self.get_changelist(request, Book, modeladmin)
    411411
    412412        # Make sure the correct queryset is returned
    413         queryset = changelist.get_query_set(request)
     413        queryset = changelist.get_queryset(request)
    414414        self.assertEqual(list(queryset), [self.bio_book])
    415415
    416416        # Make sure the correct choice is selected
    class ListFiltersTests(TestCase):  
    424424        changelist = self.get_changelist(request, Book, modeladmin)
    425425
    426426        # Make sure the correct queryset is returned
    427         queryset = changelist.get_query_set(request)
     427        queryset = changelist.get_queryset(request)
    428428        self.assertEqual(list(queryset), [self.gipsy_book, self.djangonaut_book])
    429429
    430430        # Make sure the correct choice is selected
    class ListFiltersTests(TestCase):  
    438438        changelist = self.get_changelist(request, Book, modeladmin)
    439439
    440440        # Make sure the correct queryset is returned
    441         queryset = changelist.get_query_set(request)
     441        queryset = changelist.get_queryset(request)
    442442        self.assertEqual(list(queryset), [self.django_book])
    443443
    444444        # Make sure the correct choice is selected
    class ListFiltersTests(TestCase):  
    457457        changelist = self.get_changelist(request, Book, modeladmin)
    458458
    459459        # Make sure the correct queryset is returned
    460         queryset = changelist.get_query_set(request)
     460        queryset = changelist.get_queryset(request)
    461461        self.assertEqual(list(queryset), list(Book.objects.all().order_by('-id')))
    462462
    463463        # Make sure the correct choice is selected
    class ListFiltersTests(TestCase):  
    474474        changelist = self.get_changelist(request, Book, modeladmin)
    475475
    476476        # Make sure the correct queryset is returned
    477         queryset = changelist.get_query_set(request)
     477        queryset = changelist.get_queryset(request)
    478478        self.assertEqual(list(queryset), [])
    479479
    480480        # Make sure the correct choice is selected
    class ListFiltersTests(TestCase):  
    491491        changelist = self.get_changelist(request, Book, modeladmin)
    492492
    493493        # Make sure the correct queryset is returned
    494         queryset = changelist.get_query_set(request)
     494        queryset = changelist.get_queryset(request)
    495495        self.assertEqual(list(queryset), [self.bio_book])
    496496
    497497        # Make sure the correct choice is selected
    class ListFiltersTests(TestCase):  
    508508        changelist = self.get_changelist(request, Book, modeladmin)
    509509
    510510        # Make sure the correct queryset is returned
    511         queryset = changelist.get_query_set(request)
     511        queryset = changelist.get_queryset(request)
    512512        self.assertEqual(list(queryset), [self.gipsy_book, self.djangonaut_book])
    513513
    514514        # Make sure the correct choice is selected
    class ListFiltersTests(TestCase):  
    525525        changelist = self.get_changelist(request, Book, modeladmin)
    526526
    527527        # Make sure the correct queryset is returned
    528         queryset = changelist.get_query_set(request)
     528        queryset = changelist.get_queryset(request)
    529529        self.assertEqual(list(queryset), [self.djangonaut_book])
    530530
    531531        # Make sure the correct choices are selected
    class ListFiltersTests(TestCase):  
    615615        changelist = self.get_changelist(request, Book, modeladmin)
    616616
    617617        # Make sure the correct queryset is returned
    618         queryset = changelist.get_query_set(request)
     618        queryset = changelist.get_queryset(request)
    619619        self.assertEqual(list(queryset), [self.bio_book])
    620620
    621621        filterspec = changelist.get_filters(request)[0][-1]
    class ListFiltersTests(TestCase):  
    637637        changelist = self.get_changelist(request, Book, modeladmin)
    638638
    639639        # Make sure the correct queryset is returned
    640         queryset = changelist.get_query_set(request)
     640        queryset = changelist.get_queryset(request)
    641641        self.assertEqual(list(queryset), [self.bio_book])
    642642
    643643        # Make sure the correct choice is selected
    class ListFiltersTests(TestCase):  
    654654        changelist = self.get_changelist(request, Book, modeladmin)
    655655
    656656        # Make sure the correct queryset is returned
    657         queryset = changelist.get_query_set(request)
     657        queryset = changelist.get_queryset(request)
    658658        self.assertEqual(list(queryset), [self.bio_book])
    659659
    660660        # Make sure the correct choice is selected
    class ListFiltersTests(TestCase):  
    676676        request = self.request_factory.get('/', {'department': self.john.pk})
    677677        changelist = self.get_changelist(request, Employee, modeladmin)
    678678
    679         queryset = changelist.get_query_set(request)
     679        queryset = changelist.get_queryset(request)
    680680
    681681        self.assertEqual(list(queryset), [self.john])
    682682
    class ListFiltersTests(TestCase):  
    698698        changelist = self.get_changelist(request, Employee, modeladmin)
    699699
    700700        # Make sure the correct queryset is returned
    701         queryset = changelist.get_query_set(request)
     701        queryset = changelist.get_queryset(request)
    702702        self.assertEqual(list(queryset), [self.jack, self.john])
    703703
    704704        filterspec = changelist.get_filters(request)[0][-1]
    class ListFiltersTests(TestCase):  
    723723        changelist = self.get_changelist(request, Employee, modeladmin)
    724724
    725725        # Make sure the correct queryset is returned
    726         queryset = changelist.get_query_set(request)
     726        queryset = changelist.get_queryset(request)
    727727        self.assertEqual(list(queryset), [self.john])
    728728
    729729        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):  
    417417
    418418
    419419class CustomChangeList(ChangeList):
    420     def get_query_set(self, request):
     420    def get_queryset(self, request):
    421421        return self.root_query_set.filter(pk=9999) # Does not exist
    422422
    423423
  • 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):  
    3737        return self.name
    3838
    3939class 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)
    4242
    4343@python_2_unicode_compatible
    4444class 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):  
    1010    """
    1111    A manager that filters out non-public instances.
    1212    """
    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)
    1515
    1616@python_2_unicode_compatible
    1717class 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
    - +  
     1from __future__ import unicode_literals
     2import warnings
     3
     4from django.test.testcases import SimpleTestCase
     5from django.utils import six
     6from django.utils.deprecation import DeprecatedGetQuerySet
     7from django.core.exceptions import ImproperlyConfigured
     8
     9
     10class 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  
    77
    88
    99class 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')
    1212
    1313
    1414class 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')
    1717
    1818
    1919class 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)
    2222
    2323
    2424class 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):  
    10741074                return 'awesomeness'
    10751075            def get_choices(self, request):
    10761076                return (('bit', 'A bit awesome'), ('very', 'Very awesome'), )
    1077             def get_query_set(self, cl, qs):
     1077            def get_queryset(self, cl, qs):
    10781078                return qs
    10791079
    10801080        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):  
    175175
    176176# A model and custom default manager combination.
    177177class 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()
    180180        return qs.filter(public=True, tag__name='t1')
    181181
    182182@python_2_unicode_compatible
    class Detail(models.Model):  
    196196    data = models.CharField(max_length=10)
    197197
    198198class 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")
    201201
    202202class Member(models.Model):
    203203    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  
    22
    33
    44class 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)
    77
    88class Source(models.Model):
    99    is_public = models.BooleanField()
Back to Top