Skip to content

Commit 65f81ab

Browse files
committed
Closes #17482: Ignore Branch & StagedChange in nbshell
1 parent fa1e89d commit 65f81ab

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

netbox/core/management/commands/nbshell.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
from users.models import User
1212

1313
APPS = ('circuits', 'core', 'dcim', 'extras', 'ipam', 'tenancy', 'users', 'virtualization', 'vpn', 'wireless')
14+
EXCLUDE_MODELS = (
15+
'extras.branch',
16+
'extras.stagedchange',
17+
)
1418

1519
BANNER_TEXT = """### NetBox interactive shell ({node})
1620
### Python {python} | Django {django} | NetBox {netbox}
@@ -44,12 +48,16 @@ def get_namespace(self):
4448

4549
# Gather Django models and constants from each app
4650
for app in APPS:
47-
self.django_models[app] = []
51+
models = []
4852

4953
# Load models from each app
5054
for model in apps.get_app_config(app).get_models():
51-
namespace[model.__name__] = model
52-
self.django_models[app].append(model.__name__)
55+
app_label = model._meta.app_label
56+
model_name = model._meta.model_name
57+
if f'{app_label}.{model_name}' not in EXCLUDE_MODELS:
58+
namespace[model.__name__] = model
59+
models.append(model.__name__)
60+
self.django_models[app] = sorted(models)
5361

5462
# Constants
5563
try:

0 commit comments

Comments
 (0)