@contextmanager
def secret_model():
 orig_model = None
 try:
  orig_model = loading.cache.app_models['tests']['secret']
  del loading.cache.app_models['tests']['secret']
 except KeyError:
  pass
 try:
  attrs = {'name': EncryptedCharField('Name', max_length=Secret._meta.get_field('name').max_length), 'text': EncryptedTextField('Text'), '__module__': 'django_extensions.tests.models', 'Meta': type('Meta', (object,), {'managed': False, 'db_table': Secret._meta.db_table})}
  (yield type('Secret', (models.Model,), attrs))
 except:
  raise
 finally:
  try:
   loading.cache.app_models['tests']['secret'] = orig_model
  except KeyError:
   pass

@ contextmanager def secret_model ( ) : orig_model = None try : orig_model = loading . cache . app_models [ 'tests' ] [ 'secret' ] del loading . cache . app_models [ 'tests' ] [ 'secret' ] except KeyError : pass try : attrs = { 'name' : EncryptedCharField ( 'Name' , max_length = Secret . _meta . get_field ( 'name' ) . max_length ) , 'text' : EncryptedTextField ( 'Text' ) , '__module__' : 'django_extensions.tests.models' , 'Meta' : type ( 'Meta' , ( object , ) , { 'managed' : False , 'db_table' : Secret . _meta . db_table } ) } ( yield type ( 'Secret' , ( models . Model , ) , attrs ) ) except : raise finally : try : loading . cache . app_models [ 'tests' ] [ 'secret' ] = orig_model except KeyError : pass
a context manager that yields a secret model defined at runtime .