mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #11223 - Accept app_label for reindex
This commit is contained in:
Alef Burzmali
committed by
Jeremy Stretch
parent
b6cd099117
commit
ae440c9edf
@ -27,17 +27,28 @@ class Command(BaseCommand):
|
|||||||
# Return only indexers for the specified models
|
# Return only indexers for the specified models
|
||||||
else:
|
else:
|
||||||
for label in model_names:
|
for label in model_names:
|
||||||
try:
|
labels = label.lower().split('.')
|
||||||
app_label, model_name = label.lower().split('.')
|
|
||||||
except ValueError:
|
# 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(
|
raise CommandError(
|
||||||
f"Invalid model: {label}. Model names must be in the format <app_label>.<model_name>."
|
f"Invalid model: {label}. Model names must be in the format <app_label> or <app_label>.<model_name>."
|
||||||
)
|
)
|
||||||
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
|
return indexers
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user