From a73a4255c2f25698b18d8c6eb296bfbef2b0b6e6 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 1 Dec 2021 20:36:15 +0100 Subject: [PATCH] helper to get all inheriting classes --- InvenTree/InvenTree/helpers.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index 6765180e1a..2e34c8f7d8 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -736,3 +736,18 @@ def get_objectreference(obj, type_ref: str = 'content_type', object_ref: str = ' 'model': str(model_cls._meta.verbose_name), **ret } + + +def inheritors(cls): + """ + Return all classes that are subclasses from the supplied cls + """ + subcls = set() + work = [cls] + while work: + parent = work.pop() + for child in parent.__subclasses__(): + if child not in subcls: + subcls.add(child) + work.append(child) + return subcls