mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
Revert initial model changes
This commit is contained in:
parent
e0fc1b4f41
commit
907323d46f
@ -1499,9 +1499,9 @@ class VirtualChassisFilterSet(NetBoxModelFilterSet):
|
|||||||
|
|
||||||
class CableFilterSet(TenancyFilterSet, NetBoxModelFilterSet):
|
class CableFilterSet(TenancyFilterSet, NetBoxModelFilterSet):
|
||||||
termination_a_type = ContentTypeFilter()
|
termination_a_type = ContentTypeFilter()
|
||||||
termination_a_ids = MultiValueNumberFilter()
|
termination_a_id = MultiValueNumberFilter()
|
||||||
termination_b_type = ContentTypeFilter()
|
termination_b_type = ContentTypeFilter()
|
||||||
termination_b_ids = MultiValueNumberFilter()
|
termination_b_id = MultiValueNumberFilter()
|
||||||
type = django_filters.MultipleChoiceFilter(
|
type = django_filters.MultipleChoiceFilter(
|
||||||
choices=CableTypeChoices
|
choices=CableTypeChoices
|
||||||
)
|
)
|
||||||
@ -1537,7 +1537,7 @@ class CableFilterSet(TenancyFilterSet, NetBoxModelFilterSet):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Cable
|
model = Cable
|
||||||
fields = ['id', 'label', 'length', 'length_unit', 'termination_a_ids', 'termination_b_ids']
|
fields = ['id', 'label', 'length', 'length_unit', 'termination_a_id', 'termination_b_id']
|
||||||
|
|
||||||
def search(self, queryset, name, value):
|
def search(self, queryset, name, value):
|
||||||
if not value.strip():
|
if not value.strip():
|
||||||
|
@ -83,6 +83,11 @@ class ConnectCableToDeviceForm(TenancyForm, NetBoxModelForm):
|
|||||||
'rack_id': '$termination_b_rack',
|
'rack_id': '$termination_b_rack',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
termination_b_ids = DynamicModelMultipleChoiceField(
|
||||||
|
queryset=Interface.objects.all(),
|
||||||
|
label='Name',
|
||||||
|
disabled_indicator='_occupied'
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Cable
|
model = Cable
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
# Generated by Django 4.0.4 on 2022-04-25 16:35
|
|
||||||
|
|
||||||
import django.contrib.postgres.fields
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('dcim', '0153_created_datetimefield'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='cable',
|
|
||||||
name='termination_a_ids',
|
|
||||||
field=django.contrib.postgres.fields.ArrayField(base_field=models.PositiveBigIntegerField(), null=True, size=None),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='cable',
|
|
||||||
name='termination_b_ids',
|
|
||||||
field=django.contrib.postgres.fields.ArrayField(base_field=models.PositiveBigIntegerField(), null=True, size=None),
|
|
||||||
),
|
|
||||||
]
|
|
@ -1,36 +0,0 @@
|
|||||||
from django.contrib.postgres.fields import ArrayField
|
|
||||||
from django.db import migrations
|
|
||||||
from django.db.models import ExpressionWrapper, F
|
|
||||||
|
|
||||||
|
|
||||||
def copy_termination_ids(apps, schema_editor):
|
|
||||||
"""
|
|
||||||
Copy original A & B termination ID values to new array fields.
|
|
||||||
"""
|
|
||||||
Cable = apps.get_model('dcim', 'Cable')
|
|
||||||
|
|
||||||
# TODO: Optimize data migration using F expressions
|
|
||||||
# Cable.objects.update(
|
|
||||||
# termination_a_ids=ExpressionWrapper(F('termination_a_id'), output_field=ArrayField),
|
|
||||||
# termination_b_ids=ExpressionWrapper(F('termination_b_id'), output_field=ArrayField)
|
|
||||||
# )
|
|
||||||
|
|
||||||
for cable in Cable.objects.all():
|
|
||||||
Cable.objects.filter(pk=cable.pk).update(
|
|
||||||
termination_a_ids=[cable.termination_a_id],
|
|
||||||
termination_b_ids=[cable.termination_b_id]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('dcim', '0154_cable_add_termination_id_arrays'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RunPython(
|
|
||||||
code=copy_termination_ids,
|
|
||||||
reverse_code=migrations.RunPython.noop
|
|
||||||
),
|
|
||||||
]
|
|
@ -1,25 +0,0 @@
|
|||||||
# Generated by Django 4.0.4 on 2022-04-25 20:45
|
|
||||||
|
|
||||||
from django.db import migrations
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('dcim', '0155_cable_copy_termination_ids'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterUniqueTogether(
|
|
||||||
name='cable',
|
|
||||||
unique_together=set(),
|
|
||||||
),
|
|
||||||
migrations.RemoveField(
|
|
||||||
model_name='cable',
|
|
||||||
name='termination_a_id',
|
|
||||||
),
|
|
||||||
migrations.RemoveField(
|
|
||||||
model_name='cable',
|
|
||||||
name='termination_b_id',
|
|
||||||
),
|
|
||||||
]
|
|
@ -39,9 +39,10 @@ class Cable(NetBoxModel):
|
|||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
related_name='+'
|
related_name='+'
|
||||||
)
|
)
|
||||||
termination_a_ids = ArrayField(
|
termination_a_id = models.PositiveBigIntegerField()
|
||||||
base_field=models.PositiveBigIntegerField(),
|
termination_a = GenericForeignKey(
|
||||||
null=True
|
ct_field='termination_a_type',
|
||||||
|
fk_field='termination_a_id'
|
||||||
)
|
)
|
||||||
termination_b_type = models.ForeignKey(
|
termination_b_type = models.ForeignKey(
|
||||||
to=ContentType,
|
to=ContentType,
|
||||||
@ -49,9 +50,10 @@ class Cable(NetBoxModel):
|
|||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
related_name='+'
|
related_name='+'
|
||||||
)
|
)
|
||||||
termination_b_ids = ArrayField(
|
termination_b_id = models.PositiveBigIntegerField()
|
||||||
base_field=models.PositiveBigIntegerField(),
|
termination_b = GenericForeignKey(
|
||||||
null=True
|
ct_field='termination_b_type',
|
||||||
|
fk_field='termination_b_id'
|
||||||
)
|
)
|
||||||
type = models.CharField(
|
type = models.CharField(
|
||||||
max_length=50,
|
max_length=50,
|
||||||
@ -114,6 +116,10 @@ class Cable(NetBoxModel):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['pk']
|
ordering = ['pk']
|
||||||
|
unique_together = (
|
||||||
|
('termination_a_type', 'termination_a_id'),
|
||||||
|
('termination_b_type', 'termination_b_id'),
|
||||||
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user