Ticket #22236: 22236-1.diff

File 22236-1.diff, 3.0 KB (added by Claude Paroz, 11 years ago)
  • django/db/models/base.py

    diff --git a/django/db/models/base.py b/django/db/models/base.py
    index e0bb169..589d793 100644
    a b import warnings  
    77
    88from django.apps import apps
    99from django.apps.config import MODELS_MODULE_NAME
    10 import django.db.models.manager  # NOQA: Imported to register signal handler.
    1110from django.conf import settings
    1211from django.core import checks
    1312from django.core.exceptions import (ObjectDoesNotExist,
    1413    MultipleObjectsReturned, FieldError, ValidationError, NON_FIELD_ERRORS)
     14from django.db import (router, transaction, DatabaseError,
     15    DEFAULT_DB_ALIAS)
     16from django.db.models.deletion import Collector
    1517from django.db.models.fields import AutoField, FieldDoesNotExist
    1618from django.db.models.fields.related import (ForeignObjectRel, ManyToOneRel,
    1719    OneToOneField, add_lazy_relation)
    18 from django.db import (router, transaction, DatabaseError,
    19     DEFAULT_DB_ALIAS)
     20from django.db.models.manager import ensure_default_manager
     21from django.db.models.options import Options
    2022from django.db.models.query import Q
    2123from django.db.models.query_utils import DeferredAttribute, deferred_class_factory
    22 from django.db.models.deletion import Collector
    23 from django.db.models.options import Options
    2424from django.db.models import signals
    2525from django.utils import six
    2626from django.utils.deprecation import RemovedInDjango19Warning
    class ModelBase(type):  
    353353            cls.get_absolute_url = update_wrapper(curry(get_absolute_url, opts, cls.get_absolute_url),
    354354                                                  cls.get_absolute_url)
    355355
     356        ensure_default_manager(cls)
    356357        signals.class_prepared.send(sender=cls)
    357358
    358359
  • django/db/models/manager.py

    diff --git a/django/db/models/manager.py b/django/db/models/manager.py
    index 4ab9174..6d77ef5 100644
    a b import inspect  
    33
    44from django.db import router
    55from django.db.models.query import QuerySet
    6 from django.db.models import signals
    76from django.db.models.fields import FieldDoesNotExist
    87from django.utils import six
    98from django.utils.encoding import python_2_unicode_compatible
    109
    1110
    12 def ensure_default_manager(sender, **kwargs):
     11def ensure_default_manager(cls):
    1312    """
    1413    Ensures that a Model subclass contains a default manager  and sets the
    1514    _default_manager attribute on the class. Also sets up the _base_manager
    1615    points to a plain Manager instance (which could be the same as
    1716    _default_manager if it's not a subclass of Manager).
    1817    """
    19     cls = sender
    2018    if cls._meta.abstract:
    2119        setattr(cls, 'objects', AbstractManagerDescriptor(cls))
    2220        return
    def ensure_default_manager(sender, **kwargs):  
    4846                    return
    4947            raise AssertionError("Should never get here. Please report a bug, including your model and model manager setup.")
    5048
    51 signals.class_prepared.connect(ensure_default_manager)
    52 
    5349
    5450@python_2_unicode_compatible
    5551class BaseManager(object):
Back to Top