mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 17:08:41 -06:00
13757 Fix ConfigContext reference to DeviceType (#13804)
* 13757 do prefetch to work around Django issue with vars in init (DeviceType) * 13757 use self.__dict to access vars in init * 13757 change test
This commit is contained in:
parent
35bcc2ce9d
commit
8e251ac33c
@ -98,10 +98,10 @@ class Cable(PrimaryModel):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
# A copy of the PK to be used by __str__ in case the object is deleted
|
# A copy of the PK to be used by __str__ in case the object is deleted
|
||||||
self._pk = self.pk
|
self._pk = self.__dict__.get('id')
|
||||||
|
|
||||||
# Cache the original status so we can check later if it's been changed
|
# Cache the original status so we can check later if it's been changed
|
||||||
self._orig_status = self.status
|
self._orig_status = self.__dict__.get('status')
|
||||||
|
|
||||||
self._terminations_modified = False
|
self._terminations_modified = False
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ class ComponentTemplateModel(ChangeLoggedModel, TrackingModelMixin):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
# Cache the original DeviceType ID for reference under clean()
|
# Cache the original DeviceType ID for reference under clean()
|
||||||
self._original_device_type = self.device_type_id
|
self._original_device_type = self.__dict__.get('device_type_id')
|
||||||
|
|
||||||
def to_objectchange(self, action):
|
def to_objectchange(self, action):
|
||||||
objectchange = super().to_objectchange(action)
|
objectchange = super().to_objectchange(action)
|
||||||
|
@ -86,7 +86,7 @@ class ComponentModel(NetBoxModel):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
# Cache the original Device ID for reference under clean()
|
# Cache the original Device ID for reference under clean()
|
||||||
self._original_device = self.device_id
|
self._original_device = self.__dict__.get('device_id')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.label:
|
if self.label:
|
||||||
|
@ -205,11 +205,11 @@ class DeviceType(ImageAttachmentsMixin, PrimaryModel, WeightMixin):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
# Save a copy of u_height for validation in clean()
|
# Save a copy of u_height for validation in clean()
|
||||||
self._original_u_height = self.u_height
|
self._original_u_height = self.__dict__.get('u_height')
|
||||||
|
|
||||||
# Save references to the original front/rear images
|
# Save references to the original front/rear images
|
||||||
self._original_front_image = self.front_image
|
self._original_front_image = self.__dict__.get('front_image')
|
||||||
self._original_rear_image = self.rear_image
|
self._original_rear_image = self.__dict__.get('rear_image')
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('dcim:devicetype', args=[self.pk])
|
return reverse('dcim:devicetype', args=[self.pk])
|
||||||
|
@ -219,7 +219,7 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
# Cache instance's original name so we can check later whether it has changed
|
# Cache instance's original name so we can check later whether it has changed
|
||||||
self._name = self.name
|
self._name = self.__dict__.get('name')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def search_type(self):
|
def search_type(self):
|
||||||
|
@ -6,7 +6,7 @@ from django.contrib.auth import get_user_model
|
|||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from dcim.models import Site
|
from dcim.models import DeviceType, Manufacturer, Site
|
||||||
from extras.choices import *
|
from extras.choices import *
|
||||||
from extras.models import *
|
from extras.models import *
|
||||||
from utilities.testing import ViewTestCases, TestCase
|
from utilities.testing import ViewTestCases, TestCase
|
||||||
@ -434,7 +434,8 @@ class ConfigContextTestCase(
|
|||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
|
|
||||||
site = Site.objects.create(name='Site 1', slug='site-1')
|
manufacturer = Manufacturer.objects.create(name='Manufacturer 1', slug='manufacturer-1')
|
||||||
|
devicetype = DeviceType.objects.create(manufacturer=manufacturer, model='Device Type 1', slug='device-type-1')
|
||||||
|
|
||||||
# Create three ConfigContexts
|
# Create three ConfigContexts
|
||||||
for i in range(1, 4):
|
for i in range(1, 4):
|
||||||
@ -443,7 +444,7 @@ class ConfigContextTestCase(
|
|||||||
data={'foo': i}
|
data={'foo': i}
|
||||||
)
|
)
|
||||||
configcontext.save()
|
configcontext.save()
|
||||||
configcontext.sites.add(site)
|
configcontext.device_types.add(devicetype)
|
||||||
|
|
||||||
cls.form_data = {
|
cls.form_data = {
|
||||||
'name': 'Config Context X',
|
'name': 'Config Context X',
|
||||||
@ -451,11 +452,12 @@ class ConfigContextTestCase(
|
|||||||
'description': 'A new config context',
|
'description': 'A new config context',
|
||||||
'is_active': True,
|
'is_active': True,
|
||||||
'regions': [],
|
'regions': [],
|
||||||
'sites': [site.pk],
|
'sites': [],
|
||||||
'roles': [],
|
'roles': [],
|
||||||
'platforms': [],
|
'platforms': [],
|
||||||
'tenant_groups': [],
|
'tenant_groups': [],
|
||||||
'tenants': [],
|
'tenants': [],
|
||||||
|
'device_types': [devicetype.id,],
|
||||||
'tags': [],
|
'tags': [],
|
||||||
'data': '{"foo": 123}',
|
'data': '{"foo": 123}',
|
||||||
}
|
}
|
||||||
|
@ -290,8 +290,8 @@ class Prefix(GetAvailablePrefixesMixin, PrimaryModel):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
# Cache the original prefix and VRF so we can check if they have changed on post_save
|
# Cache the original prefix and VRF so we can check if they have changed on post_save
|
||||||
self._prefix = self.prefix
|
self._prefix = self.__dict__.get('prefix')
|
||||||
self._vrf_id = self.vrf_id
|
self._vrf_id = self.__dict__.get('vrf_id')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.prefix)
|
return str(self.prefix)
|
||||||
|
Loading…
Reference in New Issue
Block a user