From 062bae3bb3d6ff410a0e903543a51c1d22ae17f0 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Thu, 15 Jun 2006 14:05:33 +0000 Subject: [PATCH] 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 --- django/db/models/manager.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/django/db/models/manager.py b/django/db/models/manager.py index bfd2effd7f..f679c5492c 100644 --- a/django/db/models/manager.py +++ b/django/db/models/manager.py @@ -3,6 +3,7 @@ from django.db import backend, connection 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)