Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed the detection of when a custom manager is required because an '…

…objects'

field already exists.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3131 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 062bae3bb3d6ff410a0e903543a51c1d22ae17f0 1 parent 28e6437
@malcolmt malcolmt authored
Showing with 6 additions and 2 deletions.
  1. +6 −2 django/db/models/manager.py
View
8 django/db/models/manager.py
@@ -3,6 +3,7 @@
from django.db.models.query import QuerySet
from django.dispatch import dispatcher
from django.db.models import signals
+from django.db.models.fields import FieldDoesNotExist
from django.utils.datastructures import SortedDict
# Size of each "chunk" for get_iterator calls.
@@ -13,8 +14,11 @@ def ensure_default_manager(sender):
cls = sender
if not hasattr(cls, '_default_manager'):
# Create the default manager, if needed.
- if hasattr(cls, 'objects'):
- raise ValueError, "Model %s must specify a custom Manager, because it has a field named 'objects'" % name
+ try:
+ cls._meta.get_field('objects')
+ raise ValueError, "Model %s must specify a custom Manager, because it has a field named 'objects'" % cls.__name__
+ except FieldDoesNotExist:
+ pass
cls.add_to_class('objects', Manager())
dispatcher.connect(ensure_default_manager, signal=signals.class_prepared)
Please sign in to comment.
Something went wrong with that request. Please try again.