#NEWLINE# def ensure_default_manager( sender , **kwargs ) : #NEWLINE# #INDENT# "\n    Ensures that a Model subclass contains a default manager  and sets the\n    _default_manager attribute on the class. Also sets up the _base_manager\n    points to a plain Manager instance (which could be the same as\n    _default_manager if it's not a subclass of Manager).\n    " #NEWLINE# cls = sender #NEWLINE# if cls . _meta . abstract : #NEWLINE# #INDENT# setattr ( cls , 'objects' , AbstractManagerDescriptor ( cls ) ) #NEWLINE# return #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if cls . _meta . swapped : #NEWLINE# #INDENT# setattr ( cls , 'objects' , SwappedManagerDescriptor ( cls ) ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# if ( not getattr ( cls , '_default_manager' , None ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# cls . _meta . get_field ( 'objects' ) #NEWLINE# raise ValueError ( ( "Model %s must specify a custom Manager, because it has a field named 'objects'" % cls . __name__ ) ) #NEWLINE# #UNINDENT# except FieldDoesNotExist : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# cls . add_to_class ( 'objects' , Manager ( ) ) #NEWLINE# cls . _base_manager = cls . objects #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not getattr ( cls , '_base_manager' , None ) ) : #NEWLINE# #INDENT# default_mgr = cls . _default_manager . __class__ #NEWLINE# if ( ( default_mgr is Manager ) or getattr ( default_mgr , 'use_for_related_fields' , False ) ) : #NEWLINE# #INDENT# cls . _base_manager = cls . _default_manager #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# for base_class in default_mgr . mro ( ) [ 1 : ] : #NEWLINE# #INDENT# if ( ( base_class is Manager ) or getattr ( base_class , 'use_for_related_fields' , False ) ) : #NEWLINE# #INDENT# cls . add_to_class ( '_base_manager' , base_class ( ) ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# raise AssertionError ( 'Should never get here. Please report a bug, including your model and model manager setup.' )