diff --git a/netbox/extras/management/commands/reindex.py b/netbox/extras/management/commands/reindex.py index f519688f830..b601a1ac1cd 100644 --- a/netbox/extras/management/commands/reindex.py +++ b/netbox/extras/management/commands/reindex.py @@ -27,17 +27,28 @@ def _get_indexers(self, *model_names): # Return only indexers for the specified models else: for label in model_names: - try: - app_label, model_name = label.lower().split('.') - except ValueError: + labels = label.lower().split('.') + + # Label specifies an exact model + if len(labels) == 2: + app_label, model_name = labels + try: + idx = registry['search'][f'{app_label}.{model_name}'] + indexers[idx.model] = idx + except KeyError: + raise CommandError(f"No indexer registered for {label}") + + # Label specifies all the models of an app + elif len(labels) == 1: + app_label = labels[0] + '.' + for indexer_label, idx in registry['search'].items(): + if indexer_label.startswith(app_label): + indexers[idx.model] = idx + + else: raise CommandError( - f"Invalid model: {label}. Model names must be in the format .." + f"Invalid model: {label}. Model names must be in the format or .." ) - try: - idx = registry['search'][f'{app_label}.{model_name}'] - indexers[idx.model] = idx - except KeyError: - raise CommandError(f"No indexer registered for {label}") return indexers diff --git a/netbox/extras/migrations/0083_search.py b/netbox/extras/migrations/0083_search.py index 8f67717bbf0..0c53de638c2 100644 --- a/netbox/extras/migrations/0083_search.py +++ b/netbox/extras/migrations/0083_search.py @@ -10,7 +10,16 @@ def reindex(apps, schema_editor): # Build the search index (except during tests) if 'test' not in sys.argv: - management.call_command('reindex') + management.call_command( + 'reindex', + 'circuits', + 'dcim', + 'extras', + 'ipam', + 'tenancy', + 'virtualization', + 'wireless', + ) class Migration(migrations.Migration):