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,18 +27,29 @@ class Command(BaseCommand):
|
||||
# Return only indexers for the specified models
|
||||
else:
|
||||
for label in model_names:
|
||||
try:
|
||||
app_label, model_name = label.lower().split('.')
|
||||
except ValueError:
|
||||
raise CommandError(
|
||||
f"Invalid model: {label}. Model names must be in the format <app_label>.<model_name>."
|
||||
)
|
||||
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 <app_label> or <app_label>.<model_name>."
|
||||
)
|
||||
|
||||
return indexers
|
||||
|
||||
def handle(self, *model_labels, **kwargs):
|
||||
|
Reference in New Issue
Block a user