mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
helper to get all inheriting classes
This commit is contained in:
parent
88d8acfebd
commit
a73a4255c2
@ -736,3 +736,18 @@ def get_objectreference(obj, type_ref: str = 'content_type', object_ref: str = '
|
|||||||
'model': str(model_cls._meta.verbose_name),
|
'model': str(model_cls._meta.verbose_name),
|
||||||
**ret
|
**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
|
||||||
|
Loading…
Reference in New Issue
Block a user