From f636af9002df6b10daa75ce2fdd29cd4bf2926cd Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 12 Sep 2024 16:27:21 -0400 Subject: [PATCH] Closes #17482: Ignore Branch & StagedChange in nbshell --- netbox/core/management/commands/nbshell.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/netbox/core/management/commands/nbshell.py b/netbox/core/management/commands/nbshell.py index e26f956c89f..8f729d10acf 100644 --- a/netbox/core/management/commands/nbshell.py +++ b/netbox/core/management/commands/nbshell.py @@ -11,6 +11,10 @@ from users.models import User APPS = ('circuits', 'core', 'dcim', 'extras', 'ipam', 'tenancy', 'users', 'virtualization', 'vpn', 'wireless') +EXCLUDE_MODELS = ( + 'extras.branch', + 'extras.stagedchange', +) BANNER_TEXT = """### NetBox interactive shell ({node}) ### Python {python} | Django {django} | NetBox {netbox} @@ -44,12 +48,16 @@ def get_namespace(self): # Gather Django models and constants from each app for app in APPS: - self.django_models[app] = [] + models = [] # Load models from each app for model in apps.get_app_config(app).get_models(): - namespace[model.__name__] = model - self.django_models[app].append(model.__name__) + app_label = model._meta.app_label + model_name = model._meta.model_name + if f'{app_label}.{model_name}' not in EXCLUDE_MODELS: + namespace[model.__name__] = model + models.append(model.__name__) + self.django_models[app] = sorted(models) # Constants try: