From cf74d20255ba30a0b618b272c36167e8f624eab7 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 5 May 2022 14:29:28 -0400 Subject: [PATCH] Change CablePath.path to JSONField --- netbox/dcim/fields.py | 13 ------------- netbox/dcim/migrations/0157_cablepath.py | 3 +-- netbox/dcim/models/cables.py | 8 +++++--- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/netbox/dcim/fields.py b/netbox/dcim/fields.py index 5ec88f89a..d3afe5c08 100644 --- a/netbox/dcim/fields.py +++ b/netbox/dcim/fields.py @@ -10,7 +10,6 @@ from .lookups import PathContains __all__ = ( 'ASNField', 'MACAddressField', - 'MultiNodePathField', 'PathField', 'WWNField', ) @@ -105,16 +104,4 @@ class PathField(ArrayField): super().__init__(**kwargs) -class MultiNodePathField(ArrayField): - """ - A two-dimensional ArrayField which represents a path, with one or more nodes at each hop. Each node is - identified by a (type, ID) tuple. - """ - def __init__(self, **kwargs): - kwargs['base_field'] = ArrayField( - base_field=models.CharField(max_length=40) - ) - super().__init__(**kwargs) - - PathField.register_lookup(PathContains) diff --git a/netbox/dcim/migrations/0157_cablepath.py b/netbox/dcim/migrations/0157_cablepath.py index 0ff773cba..a40f6a10e 100644 --- a/netbox/dcim/migrations/0157_cablepath.py +++ b/netbox/dcim/migrations/0157_cablepath.py @@ -18,8 +18,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='cablepath', name='path', - field=dcim.fields.MultiNodePathField(base_field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=40), size=None), default=[], size=None), - preserve_default=False, + field=models.JSONField(default=list), ), migrations.AddField( model_name='cablepath', diff --git a/netbox/dcim/models/cables.py b/netbox/dcim/models/cables.py index 2eb4ba8cf..f72c37702 100644 --- a/netbox/dcim/models/cables.py +++ b/netbox/dcim/models/cables.py @@ -2,14 +2,14 @@ from collections import defaultdict from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType -from django.core.exceptions import ObjectDoesNotExist, ValidationError +from django.core.exceptions import ValidationError from django.db import models from django.db.models import Sum from django.urls import reverse from dcim.choices import * from dcim.constants import * -from dcim.fields import MultiNodePathField, PathField +from dcim.fields import PathField from dcim.utils import decompile_path_node, flatten_path, object_to_path_node, path_node_to_object from netbox.models import NetBoxModel from utilities.fields import ColorField @@ -288,7 +288,9 @@ class CablePath(models.Model): `is_active` is set to True only if 1) `destination` is not null, and 2) every Cable within the path has a status of "connected". """ - path = MultiNodePathField() + path = models.JSONField( + default=list + ) is_active = models.BooleanField( default=False )