Skip to content

Instantly share code, notes, and snippets.

@ychennay
Created March 18, 2020 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ychennay/268cad5b00ba98fb9b7f4746c8564271 to your computer and use it in GitHub Desktop.
Save ychennay/268cad5b00ba98fb9b7f4746c8564271 to your computer and use it in GitHub Desktop.
Examples of dynamic exceptions
if not abstract:
new_class.add_to_class(
'DoesNotExist',
subclass_exception(
'DoesNotExist',
tuple(
x.DoesNotExist for x in parents if hasattr(x, '_meta') and not x._meta.abstract
) or (ObjectDoesNotExist,),
module,
attached_to=new_class))
new_class.add_to_class('_meta', Options(meta, app_label))
new_class.add_to_class(
'MultipleObjectsReturned',
subclass_exception(
'MultipleObjectsReturned',
tuple(
x.MultipleObjectsReturned for x in parents if hasattr(x, '_meta') and not x._meta.abstract
) or (MultipleObjectsReturned,),
module,
attached_to=new_class))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment