24
24
from utilities .templatetags .builtins .filters import linkify , render_markdown
25
25
26
26
from netbox_custom_objects .constants import APP_LABEL
27
-
27
+ from netbox_custom_objects . utilities import get_custom_object_type_from_content_type
28
28
29
29
class FieldType :
30
30
@@ -335,9 +335,7 @@ def get_model_field(self, field, **kwargs):
335
335
if content_type .app_label == APP_LABEL :
336
336
from netbox_custom_objects .models import CustomObjectType
337
337
338
- custom_object_type_id = content_type .model .replace ("table" , "" ).replace (
339
- "model" , ""
340
- )
338
+ custom_object_type_id = get_custom_object_type_from_content_type (content_type )
341
339
custom_object_type = CustomObjectType .objects .get (pk = custom_object_type_id )
342
340
model = custom_object_type .get_model ()
343
341
else :
@@ -362,9 +360,7 @@ def get_form_field(self, field, for_csv_import=False, **kwargs):
362
360
# This is a custom object type
363
361
from netbox_custom_objects .models import CustomObjectType
364
362
365
- custom_object_type_id = content_type .model .replace ("table" , "" ).replace (
366
- "model" , ""
367
- )
363
+ custom_object_type_id = get_custom_object_type_from_content_type (content_type )
368
364
custom_object_type = CustomObjectType .objects .get (pk = custom_object_type_id )
369
365
model = custom_object_type .get_model ()
370
366
field_class = DynamicModelChoiceField
@@ -569,9 +565,7 @@ def get_through_model(self, field, model=None):
569
565
570
566
# Check if this is a self-referential M2M
571
567
content_type = ContentType .objects .get (pk = field .related_object_type_id )
572
- custom_object_type_id = content_type .model .replace ("table" , "" ).replace (
573
- "model" , ""
574
- )
568
+ custom_object_type_id = get_custom_object_type_from_content_type (content_type )
575
569
is_self_referential = (
576
570
content_type .app_label == APP_LABEL
577
571
and field .custom_object_type .id == custom_object_type_id
@@ -606,9 +600,7 @@ def get_model_field(self, field, **kwargs):
606
600
"""
607
601
# Check if this is a self-referential M2M
608
602
content_type = ContentType .objects .get (pk = field .related_object_type_id )
609
- custom_object_type_id = content_type .model .replace ("table" , "" ).replace (
610
- "model" , ""
611
- )
603
+ custom_object_type_id = get_custom_object_type_from_content_type (content_type )
612
604
# TODO: Default does not auto-populate, to new or existing objects (should it?)
613
605
kwargs .update ({"default" : field .default , "unique" : field .unique })
614
606
@@ -649,9 +641,7 @@ def get_form_field(self, field, for_csv_import=False, **kwargs):
649
641
# This is a custom object type
650
642
from netbox_custom_objects .models import CustomObjectType
651
643
652
- custom_object_type_id = content_type .model .replace ("table" , "" ).replace (
653
- "model" , ""
654
- )
644
+ custom_object_type_id = get_custom_object_type_from_content_type (content_type )
655
645
custom_object_type = CustomObjectType .objects .get (pk = custom_object_type_id )
656
646
model = custom_object_type .get_model ()
657
647
else :
@@ -711,9 +701,7 @@ def after_model_generation(self, instance, model, field_name):
711
701
if content_type .app_label == APP_LABEL :
712
702
from netbox_custom_objects .models import CustomObjectType
713
703
714
- custom_object_type_id = content_type .model .replace ("table" , "" ).replace (
715
- "model" , ""
716
- )
704
+ custom_object_type_id = get_custom_object_type_from_content_type (content_type )
717
705
custom_object_type = CustomObjectType .objects .get (pk = custom_object_type_id )
718
706
to_model = custom_object_type .get_model ()
719
707
else :
@@ -753,9 +741,7 @@ def create_m2m_table(self, instance, model, field_name):
753
741
if content_type .app_label == APP_LABEL :
754
742
from netbox_custom_objects .models import CustomObjectType
755
743
756
- custom_object_type_id = content_type .model .replace ("table" , "" ).replace (
757
- "model" , ""
758
- )
744
+ custom_object_type_id = get_custom_object_type_from_content_type (content_type )
759
745
custom_object_type = CustomObjectType .objects .get (
760
746
pk = custom_object_type_id
761
747
)
0 commit comments