Skip to content

Commit b31f185

Browse files
committed
Deprecate get_for_id() on ObjectTypeManager
1 parent 944ea00 commit b31f185

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

netbox/core/models/contenttypes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def get_by_natural_key(self, app_label, model):
4040
"""
4141
return self.get(app_label=app_label, model=model)
4242

43+
# TODO: Remove in NetBox v4.5
4344
def get_for_id(self, id):
4445
"""
4546
Retrieve an ObjectType by its primary key (numeric ID).

netbox/dcim/models/cables.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import itertools
22

33
from django.contrib.contenttypes.fields import GenericForeignKey
4+
from django.contrib.contenttypes.models import ContentType
45
from django.core.exceptions import ValidationError
56
from django.db import models
67
from django.dispatch import Signal
@@ -479,13 +480,13 @@ def save(self, *args, **kwargs):
479480
def origin_type(self):
480481
if self.path:
481482
ct_id, _ = decompile_path_node(self.path[0][0])
482-
return ObjectType.objects.get_for_id(ct_id)
483+
return ContentType.objects.get_for_id(ct_id)
483484

484485
@property
485486
def destination_type(self):
486487
if self.is_complete:
487488
ct_id, _ = decompile_path_node(self.path[-1][0])
488-
return ObjectType.objects.get_for_id(ct_id)
489+
return ContentType.objects.get_for_id(ct_id)
489490

490491
@property
491492
def _path_decompiled(self):

netbox/dcim/models/devices.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from functools import cached_property
55

66
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
7+
from django.contrib.contenttypes.models import ContentType
78
from django.core.exceptions import ValidationError
89
from django.core.files.storage import default_storage
910
from django.core.validators import MaxValueValidator, MinValueValidator
@@ -15,7 +16,6 @@
1516
from django.utils.safestring import mark_safe
1617
from django.utils.translation import gettext_lazy as _
1718

18-
from core.models import ObjectType
1919
from dcim.choices import *
2020
from dcim.constants import *
2121
from dcim.fields import MACAddressField
@@ -1328,7 +1328,7 @@ def clean(self, *args, **kwargs):
13281328
super().clean()
13291329
if self._original_assigned_object_id and self._original_assigned_object_type_id:
13301330
assigned_object = self.assigned_object
1331-
ct = ObjectType.objects.get_for_id(self._original_assigned_object_type_id)
1331+
ct = ContentType.objects.get_for_id(self._original_assigned_object_type_id)
13321332
original_assigned_object = ct.get_object_for_this_type(pk=self._original_assigned_object_id)
13331333

13341334
if (

netbox/ipam/models/ip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import netaddr
22
from django.contrib.contenttypes.fields import GenericForeignKey
3+
from django.contrib.contenttypes.models import ContentType
34
from django.core.exceptions import ValidationError
45
from django.db import models
56
from django.db.models import F
67
from django.db.models.functions import Cast
78
from django.utils.functional import cached_property
89
from django.utils.translation import gettext_lazy as _
910

10-
from core.models import ObjectType
1111
from dcim.models.mixins import CachedScopeMixin
1212
from ipam.choices import *
1313
from ipam.constants import *
@@ -917,7 +917,7 @@ def clean(self):
917917

918918
if self._original_assigned_object_id and self._original_assigned_object_type_id:
919919
parent = getattr(self.assigned_object, 'parent_object', None)
920-
ct = ObjectType.objects.get_for_id(self._original_assigned_object_type_id)
920+
ct = ContentType.objects.get_for_id(self._original_assigned_object_type_id)
921921
original_assigned_object = ct.get_object_for_this_type(pk=self._original_assigned_object_id)
922922
original_parent = getattr(original_assigned_object, 'parent_object', None)
923923

0 commit comments

Comments
 (0)