Skip to content

Commit 9af8381

Browse files
committed
Cleanup table name resolution
1 parent 26d9a62 commit 9af8381

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

netbox_custom_objects/field_types.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,27 @@
1414
from django.utils.translation import gettext_lazy as _
1515
from extras.choices import CustomFieldTypeChoices, CustomFieldUIEditableChoices
1616
from utilities.api import get_serializer_for_model
17-
from utilities.forms.fields import (CSVChoiceField, CSVMultipleChoiceField,
18-
DynamicChoiceField,
19-
DynamicMultipleChoiceField, JSONField,
20-
LaxURLField)
17+
from utilities.forms.fields import (
18+
CSVChoiceField,
19+
CSVMultipleChoiceField,
20+
DynamicChoiceField,
21+
DynamicMultipleChoiceField,
22+
JSONField,
23+
LaxURLField,
24+
)
2125
from utilities.forms.utils import add_blank_choice
22-
from utilities.forms.widgets import (APISelect, APISelectMultiple, DatePicker,
23-
DateTimePicker)
26+
from utilities.forms.widgets import (
27+
APISelect,
28+
APISelectMultiple,
29+
DatePicker,
30+
DateTimePicker,
31+
)
2432
from utilities.templatetags.builtins.filters import linkify, render_markdown
2533

2634
from netbox_custom_objects.constants import APP_LABEL
2735
from netbox_custom_objects.utilities import get_custom_object_type_from_content_type
2836

37+
2938
class FieldType:
3039

3140
def get_display_value(self, instance, field_name):
@@ -335,7 +344,9 @@ def get_model_field(self, field, **kwargs):
335344
if content_type.app_label == APP_LABEL:
336345
from netbox_custom_objects.models import CustomObjectType
337346

338-
custom_object_type_id = get_custom_object_type_from_content_type(content_type)
347+
custom_object_type_id = get_custom_object_type_from_content_type(
348+
content_type
349+
)
339350
custom_object_type = CustomObjectType.objects.get(pk=custom_object_type_id)
340351
model = custom_object_type.get_model()
341352
else:
@@ -356,11 +367,14 @@ def get_form_field(self, field, for_csv_import=False, **kwargs):
356367
content_type = ContentType.objects.get(pk=field.related_object_type_id)
357368

358369
from utilities.forms.fields import DynamicModelChoiceField
370+
359371
if content_type.app_label == APP_LABEL:
360372
# This is a custom object type
361373
from netbox_custom_objects.models import CustomObjectType
362374

363-
custom_object_type_id = get_custom_object_type_from_content_type(content_type)
375+
custom_object_type_id = get_custom_object_type_from_content_type(
376+
content_type
377+
)
364378
custom_object_type = CustomObjectType.objects.get(pk=custom_object_type_id)
365379
model = custom_object_type.get_model()
366380
field_class = DynamicModelChoiceField
@@ -641,7 +655,9 @@ def get_form_field(self, field, for_csv_import=False, **kwargs):
641655
# This is a custom object type
642656
from netbox_custom_objects.models import CustomObjectType
643657

644-
custom_object_type_id = get_custom_object_type_from_content_type(content_type)
658+
custom_object_type_id = get_custom_object_type_from_content_type(
659+
content_type
660+
)
645661
custom_object_type = CustomObjectType.objects.get(pk=custom_object_type_id)
646662
model = custom_object_type.get_model()
647663
else:
@@ -701,7 +717,9 @@ def after_model_generation(self, instance, model, field_name):
701717
if content_type.app_label == APP_LABEL:
702718
from netbox_custom_objects.models import CustomObjectType
703719

704-
custom_object_type_id = get_custom_object_type_from_content_type(content_type)
720+
custom_object_type_id = get_custom_object_type_from_content_type(
721+
content_type
722+
)
705723
custom_object_type = CustomObjectType.objects.get(pk=custom_object_type_id)
706724
to_model = custom_object_type.get_model()
707725
else:
@@ -741,7 +759,9 @@ def create_m2m_table(self, instance, model, field_name):
741759
if content_type.app_label == APP_LABEL:
742760
from netbox_custom_objects.models import CustomObjectType
743761

744-
custom_object_type_id = get_custom_object_type_from_content_type(content_type)
762+
custom_object_type_id = get_custom_object_type_from_content_type(
763+
content_type
764+
)
745765
custom_object_type = CustomObjectType.objects.get(
746766
pk=custom_object_type_id
747767
)

0 commit comments

Comments
 (0)