Django

Code

Changeset 3131

Show
Ignore:
Timestamp:
06/15/06 09:05:33 (2 years ago)
Author:
mtredinnick
Message:

Fixed the detection of when a custom manager is required because an 'objects'
field already exists.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/manager.py

    r3092 r3131  
    44from django.dispatch import dispatcher 
    55from django.db.models import signals 
     6from django.db.models.fields import FieldDoesNotExist 
    67from django.utils.datastructures import SortedDict 
    78 
     
    1415    if not hasattr(cls, '_default_manager'): 
    1516        # Create the default manager, if needed. 
    16         if hasattr(cls, 'objects'): 
    17             raise ValueError, "Model %s must specify a custom Manager, because it has a field named 'objects'" % name 
     17        try: 
     18            cls._meta.get_field('objects') 
     19            raise ValueError, "Model %s must specify a custom Manager, because it has a field named 'objects'" % cls.__name__ 
     20        except FieldDoesNotExist: 
     21            pass 
    1822        cls.add_to_class('objects', Manager()) 
    1923