diff --git a/django/db/models/base.py b/django/db/models/base.py
index e0bb169..589d793 100644
a
|
b
|
import warnings
|
7 | 7 | |
8 | 8 | from django.apps import apps |
9 | 9 | from django.apps.config import MODELS_MODULE_NAME |
10 | | import django.db.models.manager # NOQA: Imported to register signal handler. |
11 | 10 | from django.conf import settings |
12 | 11 | from django.core import checks |
13 | 12 | from django.core.exceptions import (ObjectDoesNotExist, |
14 | 13 | MultipleObjectsReturned, FieldError, ValidationError, NON_FIELD_ERRORS) |
| 14 | from django.db import (router, transaction, DatabaseError, |
| 15 | DEFAULT_DB_ALIAS) |
| 16 | from django.db.models.deletion import Collector |
15 | 17 | from django.db.models.fields import AutoField, FieldDoesNotExist |
16 | 18 | from django.db.models.fields.related import (ForeignObjectRel, ManyToOneRel, |
17 | 19 | OneToOneField, add_lazy_relation) |
18 | | from django.db import (router, transaction, DatabaseError, |
19 | | DEFAULT_DB_ALIAS) |
| 20 | from django.db.models.manager import ensure_default_manager |
| 21 | from django.db.models.options import Options |
20 | 22 | from django.db.models.query import Q |
21 | 23 | from 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 |
24 | 24 | from django.db.models import signals |
25 | 25 | from django.utils import six |
26 | 26 | from django.utils.deprecation import RemovedInDjango19Warning |
… |
… |
class ModelBase(type):
|
353 | 353 | cls.get_absolute_url = update_wrapper(curry(get_absolute_url, opts, cls.get_absolute_url), |
354 | 354 | cls.get_absolute_url) |
355 | 355 | |
| 356 | ensure_default_manager(cls) |
356 | 357 | signals.class_prepared.send(sender=cls) |
357 | 358 | |
358 | 359 | |
diff --git a/django/db/models/manager.py b/django/db/models/manager.py
index 4ab9174..6d77ef5 100644
a
|
b
|
import inspect
|
3 | 3 | |
4 | 4 | from django.db import router |
5 | 5 | from django.db.models.query import QuerySet |
6 | | from django.db.models import signals |
7 | 6 | from django.db.models.fields import FieldDoesNotExist |
8 | 7 | from django.utils import six |
9 | 8 | from django.utils.encoding import python_2_unicode_compatible |
10 | 9 | |
11 | 10 | |
12 | | def ensure_default_manager(sender, **kwargs): |
| 11 | def ensure_default_manager(cls): |
13 | 12 | """ |
14 | 13 | Ensures that a Model subclass contains a default manager and sets the |
15 | 14 | _default_manager attribute on the class. Also sets up the _base_manager |
16 | 15 | points to a plain Manager instance (which could be the same as |
17 | 16 | _default_manager if it's not a subclass of Manager). |
18 | 17 | """ |
19 | | cls = sender |
20 | 18 | if cls._meta.abstract: |
21 | 19 | setattr(cls, 'objects', AbstractManagerDescriptor(cls)) |
22 | 20 | return |
… |
… |
def ensure_default_manager(sender, **kwargs):
|
48 | 46 | return |
49 | 47 | raise AssertionError("Should never get here. Please report a bug, including your model and model manager setup.") |
50 | 48 | |
51 | | signals.class_prepared.connect(ensure_default_manager) |
52 | | |
53 | 49 | |
54 | 50 | @python_2_unicode_compatible |
55 | 51 | class BaseManager(object): |