diff --git a/djorm_pgfulltext/management/commands/update_search_field.py b/djorm_pgfulltext/management/commands/update_search_field.py index 410d2e9..c9ff096 100644 --- a/djorm_pgfulltext/management/commands/update_search_field.py +++ b/djorm_pgfulltext/management/commands/update_search_field.py @@ -9,9 +9,9 @@ class Command(BaseCommand): help = 'Update search fields' - args = "appname [model]" + args = "appname [model] [using]" - def handle(self, app=None, model=None, **options): + def handle(self, app=None, model=None, using='default', **options): if not app: raise CommandError("You must provide an app to update search fields.") @@ -46,5 +46,5 @@ def handle(self, app=None, model=None, **options): for m in app_models_for_process: print("Processing model %s..." % m, end='') - m._fts_manager.update_search_field() + m._fts_manager.update_search_field(using=using) print("Done") diff --git a/djorm_pgfulltext/models.py b/djorm_pgfulltext/models.py index a7a7a73..f6a9918 100644 --- a/djorm_pgfulltext/models.py +++ b/djorm_pgfulltext/models.py @@ -43,7 +43,12 @@ def __exit__(self, *args, **kwargs): def auto_update_search_field_handler(sender, instance, *args, **kwargs): - instance.update_search_field() + # to take using from method save() + defaults = {'using': 'default'} + + instance.update_search_field( + **{arg: kwargs.get(arg, defaults[arg]) for arg in defaults.keys()} + ) class SearchManagerMixIn(object):