Skip to content

Commit ff611e8

Browse files
committed
check apps model
1 parent 117c392 commit ff611e8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

netbox_custom_objects/field_types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -987,11 +987,11 @@ def create_m2m_table(self, instance, model, field_name):
987987
# Register the model with Django's app registry
988988
apps = model._meta.apps
989989

990-
try:
991-
through_model = apps.get_model(APP_LABEL, instance.through_model_name)
992-
except LookupError:
990+
app_models = apps.all_models[APP_LABEL]
991+
if instance.through_model_name not in app_models:
993992
apps.register_model(APP_LABEL, through)
994-
through_model = through
993+
else:
994+
through_model = apps.all_models[APP_LABEL][instance.through_model_name]
995995

996996
# Update the M2M field's through model and target model
997997
field.remote_field.through = through_model

netbox_custom_objects/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,8 @@ def wrapped_post_through_setup(self, cls):
615615
model_name = model._meta.model_name
616616
if model_name not in app_models:
617617
apps.register_model(APP_LABEL, model)
618+
else:
619+
model = apps.all_models[APP_LABEL][model_name]
618620

619621
if not manytomany_models:
620622
self._after_model_generation(attrs, model)

0 commit comments

Comments
 (0)