Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_models() and __contains__() in registries.py #48

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions django_opensearch_dsl/registries.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,20 @@ def delete(self, instance, **kwargs):
"""
self.update(instance, action="delete", **kwargs)

def get_models(self):
"""Get all models in the registry."""
return set(self._models.keys())

def get_indices(self, models=None):
"""Get all indices in the registry or the indices for a list of models."""
if models is not None:
return set(index for index, docs in self._indices.items() for doc in docs if doc.django.model in models)

return set(self._indices.keys())

def __contains__(self, model):
"""Checks that model is in registry."""
return model in self._models or model in self._related_models


registry = DocumentRegistry()