Skip to content

Commit d816775

Browse files
committed
Create contenttypes entry on CustomObjectType save
1 parent 25b8a0f commit d816775

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

netbox_custom_objects/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def object_type_name(self, object_type, include_app=True):
7070
except AttributeError:
7171
if object_type.app_label == 'netbox_custom_objects':
7272
try:
73-
model_name = self.custom_object_types.get(slug=object_type.model).name
73+
model_name = self.custom_object_types.get(name__iexact=object_type.model).name
7474
return f'Custom Objects > {model_name} (Custom)'
7575
except CustomObjectType.DoesNotExist:
7676
pass

netbox_custom_objects/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ class Meta:
6565
def __str__(self):
6666
return self.name
6767

68+
def save(self, *args, **kwargs):
69+
super().save(*args, **kwargs)
70+
content_type, _ = ContentType.objects.get_or_create(app_label='netbox_custom_objects', model=self.name.lower())
71+
6872
@property
6973
def formatted_schema(self):
7074
result = '<ul>'
@@ -632,7 +636,7 @@ def deserialize(self, value):
632636
def related_custom_object_type(self):
633637
if self.related_object_type.app_label != 'netbox_custom_objects':
634638
return None
635-
return CustomObjectType.objects.get(slug=self.related_object_type.model)
639+
return CustomObjectType.objects.get(name__iexact=self.related_object_type.model)
636640

637641
@property
638642
def related_object_queryset(self):

0 commit comments

Comments
 (0)