File tree Expand file tree Collapse file tree 1 file changed +20
-9
lines changed
netbox/extras/management/commands Expand file tree Collapse file tree 1 file changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -27,17 +27,28 @@ def _get_indexers(self, *model_names):
2727 # Return only indexers for the specified models
2828 else :
2929 for label in model_names :
30- try :
31- app_label , model_name = label .lower ().split ('.' )
32- except ValueError :
30+ labels = label .lower ().split ('.' )
31+
32+ # Label specifies an exact model
33+ if len (labels ) == 2 :
34+ app_label , model_name = labels
35+ try :
36+ idx = registry ['search' ][f'{ app_label } .{ model_name } ' ]
37+ indexers [idx .model ] = idx
38+ except KeyError :
39+ raise CommandError (f"No indexer registered for { label } " )
40+
41+ # Label specifies all the models of an app
42+ elif len (labels ) == 1 :
43+ app_label = labels [0 ] + '.'
44+ for indexer_label , idx in registry ['search' ].items ():
45+ if indexer_label .startswith (app_label ):
46+ indexers [idx .model ] = idx
47+
48+ else :
3349 raise CommandError (
34- f"Invalid model: { label } . Model names must be in the format <app_label>.<model_name>."
50+ f"Invalid model: { label } . Model names must be in the format <app_label> or <app_label> .<model_name>."
3551 )
36- try :
37- idx = registry ['search' ][f'{ app_label } .{ model_name } ' ]
38- indexers [idx .model ] = idx
39- except KeyError :
40- raise CommandError (f"No indexer registered for { label } " )
4152
4253 return indexers
4354
You can’t perform that action at this time.
0 commit comments