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

feat: add auto_indexing param to register decorator function #305

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions algoliasearch_django/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def inner(*args, **kwargs):
return inner


def register(model):
def register(model, auto_indexing=None):
"""
Register the given model class and wrapped AlgoliaIndex class with the Algolia engine:

Expand All @@ -49,7 +49,7 @@ def _algolia_engine_wrapper(index_class):
if not issubclass(index_class, AlgoliaIndex):
raise ValueError('Wrapped class must subclass AlgoliaIndex.')

register(model, index_class)
register(model, index_class, auto_indexing)

return index_class
return _algolia_engine_wrapper
Expand Down
5 changes: 3 additions & 2 deletions algoliasearch_django/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ def register(self, model, index_cls=AlgoliaIndex, auto_indexing=None):
index_obj = index_cls(model, self.client, self.__settings)
self.__registered_models[model] = index_obj

if (isinstance(auto_indexing, bool) and
auto_indexing) or self.__auto_indexing:
enable_auto_indexing = auto_indexing if isinstance(auto_indexing, bool) else self.__auto_indexing

if enable_auto_indexing:
# Connect to the signalling framework.
post_save.connect(self.__post_save_receiver, model)
pre_delete.connect(self.__pre_delete_receiver, model)
Expand Down