diff --git a/apis_core/apis_entities/templatetags/apis_templatetags.py b/apis_core/apis_entities/templatetags/apis_templatetags.py index ad4d5c3d5..8db8e5bb0 100644 --- a/apis_core/apis_entities/templatetags/apis_templatetags.py +++ b/apis_core/apis_entities/templatetags/apis_templatetags.py @@ -2,6 +2,8 @@ from django import template from apis_core.utils import caching from apis_core.utils.helpers import triple_sidebar +from django.contrib.contenttypes.models import ContentType +from apis_core.apis_entities.models import AbstractEntity register = template.Library() @@ -29,6 +31,26 @@ def entities_list_links(): return entities_links +def is_entity(content_type: ContentType): + model_class = content_type.model_class() + return model_class is not None and issubclass(model_class, AbstractEntity) + + +@register.simple_tag +def entities_content_types(): + """ + Retrieve all models which inherit from AbstractEntity class + and return their class name and verbose name. + """ + entities = list( + filter( + lambda content_type: is_entity(content_type), + ContentType.objects.all(), + ) + ) + return entities + + @register.simple_tag(takes_context=True) def object_relations(context, detail=True): obj = context["object"] diff --git a/apis_core/core/templates/base.html b/apis_core/core/templates/base.html index 7ad69be8e..baed57021 100644 --- a/apis_core/core/templates/base.html +++ b/apis_core/core/templates/base.html @@ -101,10 +101,10 @@