Revert initial model changes

This commit is contained in:
jeremystretch 2022-04-29 09:16:49 -04:00
parent e0fc1b4f41
commit 907323d46f
6 changed files with 20 additions and 94 deletions

View File

@ -1499,9 +1499,9 @@ class VirtualChassisFilterSet(NetBoxModelFilterSet):
class CableFilterSet(TenancyFilterSet, NetBoxModelFilterSet):
termination_a_type = ContentTypeFilter()
termination_a_ids = MultiValueNumberFilter()
termination_a_id = MultiValueNumberFilter()
termination_b_type = ContentTypeFilter()
termination_b_ids = MultiValueNumberFilter()
termination_b_id = MultiValueNumberFilter()
type = django_filters.MultipleChoiceFilter(
choices=CableTypeChoices
)
@ -1537,7 +1537,7 @@ class CableFilterSet(TenancyFilterSet, NetBoxModelFilterSet):
class Meta:
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):
if not value.strip():

View File

@ -83,6 +83,11 @@ class ConnectCableToDeviceForm(TenancyForm, NetBoxModelForm):
'rack_id': '$termination_b_rack',
}
)
termination_b_ids = DynamicModelMultipleChoiceField(
queryset=Interface.objects.all(),
label='Name',
disabled_indicator='_occupied'
)
class Meta:
model = Cable

View File

@ -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),
),
]

View File

@ -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
),
]

View File

@ -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',
),
]

View File

@ -39,9 +39,10 @@ class Cable(NetBoxModel):
on_delete=models.PROTECT,
related_name='+'
)
termination_a_ids = ArrayField(
base_field=models.PositiveBigIntegerField(),
null=True
termination_a_id = models.PositiveBigIntegerField()
termination_a = GenericForeignKey(
ct_field='termination_a_type',
fk_field='termination_a_id'
)
termination_b_type = models.ForeignKey(
to=ContentType,
@ -49,9 +50,10 @@ class Cable(NetBoxModel):
on_delete=models.PROTECT,
related_name='+'
)
termination_b_ids = ArrayField(
base_field=models.PositiveBigIntegerField(),
null=True
termination_b_id = models.PositiveBigIntegerField()
termination_b = GenericForeignKey(
ct_field='termination_b_type',
fk_field='termination_b_id'
)
type = models.CharField(
max_length=50,
@ -114,6 +116,10 @@ class Cable(NetBoxModel):
class Meta:
ordering = ['pk']
unique_together = (
('termination_a_type', 'termination_a_id'),
('termination_b_type', 'termination_b_id'),
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)