mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-19 03:42:25 -06:00
Rename CustomField.content_types to object_types & use ObjectType proxy
This commit is contained in:
@@ -10,6 +10,7 @@ from django.test import Client, TestCase as _TestCase
|
||||
from netaddr import IPNetwork
|
||||
from taggit.managers import TaggableManager
|
||||
|
||||
from core.models import ObjectType
|
||||
from users.models import ObjectPermission
|
||||
from utilities.permissions import resolve_permission_ct
|
||||
from utilities.utils import content_type_identifier
|
||||
@@ -112,7 +113,7 @@ class ModelTestCase(TestCase):
|
||||
# Handle ManyToManyFields
|
||||
if value and type(field) in (ManyToManyField, TaggableManager):
|
||||
|
||||
if field.related_model is ContentType and api:
|
||||
if field.related_model in (ContentType, ObjectType) and api:
|
||||
model_dict[key] = sorted([content_type_identifier(ct) for ct in value])
|
||||
else:
|
||||
model_dict[key] = sorted([obj.pk for obj in value])
|
||||
@@ -120,8 +121,8 @@ class ModelTestCase(TestCase):
|
||||
elif api:
|
||||
|
||||
# Replace ContentType numeric IDs with <app_label>.<model>
|
||||
if type(getattr(instance, key)) is ContentType:
|
||||
ct = ContentType.objects.get(pk=value)
|
||||
if type(getattr(instance, key)) in (ContentType, ObjectType):
|
||||
ct = ObjectType.objects.get(pk=value)
|
||||
model_dict[key] = content_type_identifier(ct)
|
||||
|
||||
# Convert IPNetwork instances to strings
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import urllib.parse
|
||||
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.test import Client, TestCase, override_settings
|
||||
from django.urls import reverse
|
||||
from rest_framework import status
|
||||
|
||||
from core.models import ObjectType
|
||||
from dcim.models import Region, Site
|
||||
from extras.choices import CustomFieldTypeChoices
|
||||
from extras.models import CustomField
|
||||
@@ -240,10 +238,10 @@ class APIDocsTestCase(TestCase):
|
||||
self.client = Client()
|
||||
|
||||
# Populate a CustomField to activate CustomFieldSerializer
|
||||
content_type = ContentType.objects.get_for_model(Site)
|
||||
object_type = ObjectType.objects.get_for_model(Site)
|
||||
self.cf_text = CustomField(type=CustomFieldTypeChoices.TYPE_TEXT, name='test')
|
||||
self.cf_text.save()
|
||||
self.cf_text.content_types.set([content_type])
|
||||
self.cf_text.object_types.set([object_type])
|
||||
self.cf_text.save()
|
||||
|
||||
def test_api_docs(self):
|
||||
|
||||
Reference in New Issue
Block a user