Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions netbox_custom_objects/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import decimal
import re
import warnings
from datetime import date, datetime

import django_filters
Expand Down Expand Up @@ -34,8 +35,8 @@
ExportTemplatesMixin,
JournalingMixin,
NotificationsMixin,
get_model_features,
TagsMixin,
get_model_features,
)
from netbox.registry import registry
from utilities import filters
Expand Down Expand Up @@ -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:
Expand Down