diff --git a/netbox_custom_objects/models.py b/netbox_custom_objects/models.py index 24ce8b5..c4fdba0 100644 --- a/netbox_custom_objects/models.py +++ b/netbox_custom_objects/models.py @@ -1,5 +1,6 @@ import decimal import re +import warnings from datetime import date, datetime import django_filters @@ -34,8 +35,8 @@ ExportTemplatesMixin, JournalingMixin, NotificationsMixin, - get_model_features, TagsMixin, + get_model_features, ) from netbox.registry import registry from utilities import filters @@ -437,15 +438,22 @@ def wrapped_post_through_setup(self, cls): TM.post_through_setup = wrapped_post_through_setup - try: - model = type( - str(model_name), - (CustomObject, models.Model), - attrs, + # Suppress RuntimeWarning about model already being registered + # TODO: Remove this once we have a better way to handle model registration + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", category=RuntimeWarning, message=".*was already registered.*" ) - finally: - # Restore the original method - TM.post_through_setup = original_post_through_setup + + try: + model = type( + str(model_name), + (CustomObject, models.Model), + attrs, + ) + finally: + # Restore the original method + TM.post_through_setup = original_post_through_setup # Register the main model with Django's app registry try: