mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Change CablePath.path to JSONField
This commit is contained in:
@ -10,7 +10,6 @@ from .lookups import PathContains
|
|||||||
__all__ = (
|
__all__ = (
|
||||||
'ASNField',
|
'ASNField',
|
||||||
'MACAddressField',
|
'MACAddressField',
|
||||||
'MultiNodePathField',
|
|
||||||
'PathField',
|
'PathField',
|
||||||
'WWNField',
|
'WWNField',
|
||||||
)
|
)
|
||||||
@ -105,16 +104,4 @@ class PathField(ArrayField):
|
|||||||
super().__init__(**kwargs)
|
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)
|
PathField.register_lookup(PathContains)
|
||||||
|
@ -18,8 +18,7 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='cablepath',
|
model_name='cablepath',
|
||||||
name='path',
|
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),
|
field=models.JSONField(default=list),
|
||||||
preserve_default=False,
|
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='cablepath',
|
model_name='cablepath',
|
||||||
|
@ -2,14 +2,14 @@ from collections import defaultdict
|
|||||||
|
|
||||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||||
from django.contrib.contenttypes.models import ContentType
|
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 import models
|
||||||
from django.db.models import Sum
|
from django.db.models import Sum
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from dcim.choices import *
|
from dcim.choices import *
|
||||||
from dcim.constants 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 dcim.utils import decompile_path_node, flatten_path, object_to_path_node, path_node_to_object
|
||||||
from netbox.models import NetBoxModel
|
from netbox.models import NetBoxModel
|
||||||
from utilities.fields import ColorField
|
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
|
`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".
|
"connected".
|
||||||
"""
|
"""
|
||||||
path = MultiNodePathField()
|
path = models.JSONField(
|
||||||
|
default=list
|
||||||
|
)
|
||||||
is_active = models.BooleanField(
|
is_active = models.BooleanField(
|
||||||
default=False
|
default=False
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user