Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion elastimorphic/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class ElastimorphicConfig(AppConfig):
def ready(self):
def register_subclasses(klass):
for subclass in klass.__subclasses__():
polymorphic_indexable_registry.register(subclass)
# only register concrete models
meta = getattr(subclass, "_meta")
if meta and not getattr(meta, "abstract"):
polymorphic_indexable_registry.register(subclass)
register_subclasses(subclass)
register_subclasses(PolymorphicIndexable)
14 changes: 13 additions & 1 deletion elastimorphic/tests/testapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,16 @@ def get_mapping_properties(cls):
@classmethod
def get_serializer_class(cls):
from .serializers import GrandchildIndexableSerializer
return GrandchildIndexableSerializer
return GrandchildIndexableSerializer


class PolyMixin(PolymorphicIndexable, models.Model):
itsa = models.TextField(default="", blank=True)
mixin = models.TextField(default="", blank=True)

class Meta:
abstract = True


class MixedIndexable(SeparateIndexable, PolyMixin):
pass
16 changes: 14 additions & 2 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
ChildIndexable,
GrandchildIndexable,
ParentIndexable,
SeparateIndexable)
SeparateIndexable,
MixedIndexable)


class IndexableTestCase(BaseIndexableTestCase):
Expand Down Expand Up @@ -50,6 +51,7 @@ def test_mapping_type_names(self):
self.assertEqual(
SeparateIndexable.get_mapping_type_names(), [
SeparateIndexable.get_mapping_type_name(),
MixedIndexable.get_mapping_type_name(),
]
)

Expand Down Expand Up @@ -247,7 +249,17 @@ def test_registry_has_models(self):
self.assertTrue(polymorphic_indexable_registry.all_models)
self.assertTrue(polymorphic_indexable_registry.families)
types = polymorphic_indexable_registry.get_doctypes(ParentIndexable)
desired_classes = set([ParentIndexable, ChildIndexable, GrandchildIndexable])
desired_classes = set([
ParentIndexable, ChildIndexable, GrandchildIndexable
])
result_classes = set()
for name, klass in types.items():
result_classes.add(klass)
self.assertEqual(desired_classes, result_classes)

def test_registry_has_no_abstract_models(self):
types = polymorphic_indexable_registry.get_doctypes(SeparateIndexable)
desired_classes = set([SeparateIndexable, MixedIndexable])
result_classes = set()
for name, klass in types.items():
result_classes.add(klass)
Expand Down