Django

Code

Show
Ignore:
Timestamp:
09/02/08 04:04:54 (4 months ago)
Author:
mtredinnick
Message:

Fixed #7154 -- Inherit all model managers from abstract base classes.
Also added documentation describing how manager inheritance works (and when
manager aren't inherited). Based on some patches from sebastian_noack and
emulbreh.

Files:

Legend:

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

    r8223 r8851  
    2424    def __init__(self): 
    2525        super(Manager, self).__init__() 
    26         # Increase the creation counter, and save our local copy. 
    27         self.creation_counter = Manager.creation_counter 
    28         Manager.creation_counter += 1 
     26        self._set_creation_counter() 
    2927        self.model = None 
     28        self._inherited = False 
    3029 
    3130    def contribute_to_class(self, model, name): 
     
    3534        if not getattr(model, '_default_manager', None) or self.creation_counter < model._default_manager.creation_counter: 
    3635            model._default_manager = self 
     36        if model._meta.abstract or self._inherited: 
     37            model._meta.abstract_managers.append((self.creation_counter, name, 
     38                    self)) 
     39 
     40    def _set_creation_counter(self): 
     41        """ 
     42        Sets the creation counter value for this instance and increments the 
     43        class-level copy. 
     44        """ 
     45        self.creation_counter = Manager.creation_counter 
     46        Manager.creation_counter += 1 
    3747 
    3848    def _copy_to_model(self, model): 
     
    4454        assert issubclass(model, self.model) 
    4555        mgr = copy.copy(self) 
     56        mgr._set_creation_counter() 
    4657        mgr.model = model 
     58        mgr._inherited = True 
    4759        return mgr 
    4860