Deprecate get_for_id() on ObjectTypeManager
Some checks are pending
CI / build (20.x, 3.10) (push) Waiting to run
CI / build (20.x, 3.11) (push) Waiting to run
CI / build (20.x, 3.12) (push) Waiting to run

This commit is contained in:
Jeremy Stretch 2025-07-24 10:24:04 -04:00
parent 944ea00a86
commit b31f185f42
4 changed files with 8 additions and 6 deletions

View File

@ -40,6 +40,7 @@ class ObjectTypeManager(models.Manager):
""" """
return self.get(app_label=app_label, model=model) return self.get(app_label=app_label, model=model)
# TODO: Remove in NetBox v4.5
def get_for_id(self, id): def get_for_id(self, id):
""" """
Retrieve an ObjectType by its primary key (numeric ID). Retrieve an ObjectType by its primary key (numeric ID).

View File

@ -1,6 +1,7 @@
import itertools import itertools
from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.db import models from django.db import models
from django.dispatch import Signal from django.dispatch import Signal
@ -479,13 +480,13 @@ class CablePath(models.Model):
def origin_type(self): def origin_type(self):
if self.path: if self.path:
ct_id, _ = decompile_path_node(self.path[0][0]) ct_id, _ = decompile_path_node(self.path[0][0])
return ObjectType.objects.get_for_id(ct_id) return ContentType.objects.get_for_id(ct_id)
@property @property
def destination_type(self): def destination_type(self):
if self.is_complete: if self.is_complete:
ct_id, _ = decompile_path_node(self.path[-1][0]) ct_id, _ = decompile_path_node(self.path[-1][0])
return ObjectType.objects.get_for_id(ct_id) return ContentType.objects.get_for_id(ct_id)
@property @property
def _path_decompiled(self): def _path_decompiled(self):

View File

@ -4,6 +4,7 @@ import yaml
from functools import cached_property from functools import cached_property
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.core.files.storage import default_storage from django.core.files.storage import default_storage
from django.core.validators import MaxValueValidator, MinValueValidator from django.core.validators import MaxValueValidator, MinValueValidator
@ -15,7 +16,6 @@ from django.urls import reverse
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from core.models import ObjectType
from dcim.choices import * from dcim.choices import *
from dcim.constants import * from dcim.constants import *
from dcim.fields import MACAddressField from dcim.fields import MACAddressField
@ -1328,7 +1328,7 @@ class MACAddress(PrimaryModel):
super().clean() super().clean()
if self._original_assigned_object_id and self._original_assigned_object_type_id: if self._original_assigned_object_id and self._original_assigned_object_type_id:
assigned_object = self.assigned_object assigned_object = self.assigned_object
ct = ObjectType.objects.get_for_id(self._original_assigned_object_type_id) ct = ContentType.objects.get_for_id(self._original_assigned_object_type_id)
original_assigned_object = ct.get_object_for_this_type(pk=self._original_assigned_object_id) original_assigned_object = ct.get_object_for_this_type(pk=self._original_assigned_object_id)
if ( if (

View File

@ -1,5 +1,6 @@
import netaddr import netaddr
from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.db import models from django.db import models
from django.db.models import F from django.db.models import F
@ -7,7 +8,6 @@ from django.db.models.functions import Cast
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from core.models import ObjectType
from dcim.models.mixins import CachedScopeMixin from dcim.models.mixins import CachedScopeMixin
from ipam.choices import * from ipam.choices import *
from ipam.constants import * from ipam.constants import *
@ -917,7 +917,7 @@ class IPAddress(ContactsMixin, PrimaryModel):
if self._original_assigned_object_id and self._original_assigned_object_type_id: if self._original_assigned_object_id and self._original_assigned_object_type_id:
parent = getattr(self.assigned_object, 'parent_object', None) parent = getattr(self.assigned_object, 'parent_object', None)
ct = ObjectType.objects.get_for_id(self._original_assigned_object_type_id) ct = ContentType.objects.get_for_id(self._original_assigned_object_type_id)
original_assigned_object = ct.get_object_for_this_type(pk=self._original_assigned_object_id) original_assigned_object = ct.get_object_for_this_type(pk=self._original_assigned_object_id)
original_parent = getattr(original_assigned_object, 'parent_object', None) original_parent = getattr(original_assigned_object, 'parent_object', None)