1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #7858: Standardize the representation of content types across import & export functions

This commit is contained in:
jeremystretch
2021-11-17 11:02:22 -05:00
parent 6f7fbf7686
commit 9de179cba8
5 changed files with 35 additions and 11 deletions

View File

@@ -10,6 +10,7 @@ from taggit.managers import TaggableManager
from users.models import ObjectPermission
from utilities.permissions import resolve_permission_ct
from utilities.utils import content_type_identifier
from .utils import extract_form_failures
__all__ = (
@@ -110,7 +111,7 @@ class ModelTestCase(TestCase):
if value and type(field) in (ManyToManyField, TaggableManager):
if field.related_model is ContentType and api:
model_dict[key] = sorted([f'{ct.app_label}.{ct.model}' for ct in value])
model_dict[key] = sorted([content_type_identifier(ct) for ct in value])
else:
model_dict[key] = sorted([obj.pk for obj in value])
@@ -119,7 +120,7 @@ class ModelTestCase(TestCase):
# Replace ContentType numeric IDs with <app_label>.<model>
if type(getattr(instance, key)) is ContentType:
ct = ContentType.objects.get(pk=value)
model_dict[key] = f'{ct.app_label}.{ct.model}'
model_dict[key] = content_type_identifier(ct)
# Convert IPNetwork instances to strings
elif type(value) is IPNetwork: