Skip to content

Commit 2cfb0d3

Browse files
committed
183 fix deletion of COT when Object Field pointing to it
1 parent f2e2da1 commit 2cfb0d3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

netbox_custom_objects/views.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from django.urls import reverse
1010
from django.utils.translation import gettext_lazy as _
1111
from django.views.generic import View
12-
from extras.choices import CustomFieldUIVisibleChoices
12+
from extras.choices import CustomFieldTypeChoices, CustomFieldUIVisibleChoices
1313
from extras.forms import JournalEntryForm
1414
from extras.models import JournalEntry
1515
from extras.tables import JournalEntryTable
@@ -189,6 +189,16 @@ def _get_dependent_objects(self, obj):
189189
dependent_objects = super()._get_dependent_objects(obj)
190190
model = obj.get_model()
191191
dependent_objects[model] = list(model.objects.all())
192+
193+
# Find CustomObjectTypeFields that reference this CustomObjectType
194+
referencing_fields = CustomObjectTypeField.objects.filter(
195+
related_object_type=obj.content_type
196+
)
197+
198+
# Add the CustomObjectTypeFields that reference this CustomObjectType
199+
if referencing_fields.exists():
200+
dependent_objects[CustomObjectTypeField] = list(referencing_fields)
201+
192202
return dependent_objects
193203

194204

0 commit comments

Comments
 (0)