mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 09:51:22 -06:00
Standardized naming of reverse relationships from component templates to DeviceType
This commit is contained in:
parent
cf9c8f35a0
commit
3ea2978df4
@ -355,19 +355,19 @@ class DeviceTypeFilter(CustomFieldFilterSet, django_filters.FilterSet):
|
|||||||
|
|
||||||
def _console_ports(self, queryset, name, value):
|
def _console_ports(self, queryset, name, value):
|
||||||
value = value.strip()
|
value = value.strip()
|
||||||
return queryset.exclude(console_port_templates__isnull=bool(value))
|
return queryset.exclude(consoleport_templates__isnull=bool(value))
|
||||||
|
|
||||||
def _console_server_ports(self, queryset, name, value):
|
def _console_server_ports(self, queryset, name, value):
|
||||||
value = value.strip()
|
value = value.strip()
|
||||||
return queryset.exclude(cs_port_templates__isnull=bool(value))
|
return queryset.exclude(consoleserverport_templates__isnull=bool(value))
|
||||||
|
|
||||||
def _power_ports(self, queryset, name, value):
|
def _power_ports(self, queryset, name, value):
|
||||||
value = value.strip()
|
value = value.strip()
|
||||||
return queryset.exclude(power_port_templates__isnull=bool(value))
|
return queryset.exclude(powerport_templates__isnull=bool(value))
|
||||||
|
|
||||||
def _power_outlets(self, queryset, name, value):
|
def _power_outlets(self, queryset, name, value):
|
||||||
value = value.strip()
|
value = value.strip()
|
||||||
return queryset.exclude(power_outlet_templates__isnull=bool(value))
|
return queryset.exclude(poweroutlet_templates__isnull=bool(value))
|
||||||
|
|
||||||
def _interfaces(self, queryset, name, value):
|
def _interfaces(self, queryset, name, value):
|
||||||
value = value.strip()
|
value = value.strip()
|
||||||
@ -376,8 +376,8 @@ class DeviceTypeFilter(CustomFieldFilterSet, django_filters.FilterSet):
|
|||||||
def _pass_through_ports(self, queryset, name, value):
|
def _pass_through_ports(self, queryset, name, value):
|
||||||
value = value.strip()
|
value = value.strip()
|
||||||
return queryset.exclude(
|
return queryset.exclude(
|
||||||
front_port_templates__isnull=bool(value),
|
frontport_templates__isnull=bool(value),
|
||||||
rear_port_templates__isnull=bool(value)
|
rearport_templates__isnull=bool(value)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -807,7 +807,7 @@ class FrontPortTemplateCreateForm(ComponentForm):
|
|||||||
# Determine which rear port positions are occupied. These will be excluded from the list of available mappings.
|
# Determine which rear port positions are occupied. These will be excluded from the list of available mappings.
|
||||||
occupied_port_positions = [
|
occupied_port_positions = [
|
||||||
(front_port.rear_port_id, front_port.rear_port_position)
|
(front_port.rear_port_id, front_port.rear_port_position)
|
||||||
for front_port in self.parent.front_port_templates.all()
|
for front_port in self.parent.frontport_templates.all()
|
||||||
]
|
]
|
||||||
|
|
||||||
# Populate rear port choices
|
# Populate rear port choices
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
# Generated by Django 2.0.8 on 2018-10-03 17:26
|
|
||||||
|
|
||||||
import django.core.validators
|
import django.core.validators
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
@ -68,22 +66,22 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='rearporttemplate',
|
model_name='rearporttemplate',
|
||||||
name='device_type',
|
name='device_type',
|
||||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rear_port_templates', to='dcim.DeviceType'),
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rearport_templates', to='dcim.DeviceType'),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='frontporttemplate',
|
model_name='frontporttemplate',
|
||||||
name='device_type',
|
name='device_type',
|
||||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='front_port_templates', to='dcim.DeviceType'),
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='frontport_templates', to='dcim.DeviceType'),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='frontporttemplate',
|
model_name='frontporttemplate',
|
||||||
name='rear_port',
|
name='rear_port',
|
||||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='front_port_templates', to='dcim.RearPortTemplate'),
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='frontport_templates', to='dcim.RearPortTemplate'),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='frontport',
|
model_name='frontport',
|
||||||
name='rear_port',
|
name='rear_port',
|
||||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='front_ports', to='dcim.RearPort'),
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='frontports', to='dcim.RearPort'),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='frontport',
|
model_name='frontport',
|
||||||
@ -106,4 +104,26 @@ class Migration(migrations.Migration):
|
|||||||
name='frontport',
|
name='frontport',
|
||||||
unique_together={('device', 'name'), ('rear_port', 'rear_port_position')},
|
unique_together={('device', 'name'), ('rear_port', 'rear_port_position')},
|
||||||
),
|
),
|
||||||
|
|
||||||
|
# Rename reverse relationships of component templates to DeviceType
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='consoleporttemplate',
|
||||||
|
name='device_type',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='consoleport_templates', to='dcim.DeviceType'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='consoleserverporttemplate',
|
||||||
|
name='device_type',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='consoleserverport_templates', to='dcim.DeviceType'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='poweroutlettemplate',
|
||||||
|
name='device_type',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='poweroutlet_templates', to='dcim.DeviceType'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='powerporttemplate',
|
||||||
|
name='device_type',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='powerport_templates', to='dcim.DeviceType'),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
@ -965,7 +965,7 @@ class ConsolePortTemplate(ComponentTemplateModel):
|
|||||||
device_type = models.ForeignKey(
|
device_type = models.ForeignKey(
|
||||||
to='dcim.DeviceType',
|
to='dcim.DeviceType',
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name='console_port_templates'
|
related_name='consoleport_templates'
|
||||||
)
|
)
|
||||||
name = models.CharField(
|
name = models.CharField(
|
||||||
max_length=50
|
max_length=50
|
||||||
@ -986,7 +986,7 @@ class ConsoleServerPortTemplate(ComponentTemplateModel):
|
|||||||
device_type = models.ForeignKey(
|
device_type = models.ForeignKey(
|
||||||
to='dcim.DeviceType',
|
to='dcim.DeviceType',
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name='cs_port_templates'
|
related_name='consoleserverport_templates'
|
||||||
)
|
)
|
||||||
name = models.CharField(
|
name = models.CharField(
|
||||||
max_length=50
|
max_length=50
|
||||||
@ -1007,7 +1007,7 @@ class PowerPortTemplate(ComponentTemplateModel):
|
|||||||
device_type = models.ForeignKey(
|
device_type = models.ForeignKey(
|
||||||
to='dcim.DeviceType',
|
to='dcim.DeviceType',
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name='power_port_templates'
|
related_name='powerport_templates'
|
||||||
)
|
)
|
||||||
name = models.CharField(
|
name = models.CharField(
|
||||||
max_length=50
|
max_length=50
|
||||||
@ -1028,7 +1028,7 @@ class PowerOutletTemplate(ComponentTemplateModel):
|
|||||||
device_type = models.ForeignKey(
|
device_type = models.ForeignKey(
|
||||||
to='dcim.DeviceType',
|
to='dcim.DeviceType',
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name='power_outlet_templates'
|
related_name='poweroutlet_templates'
|
||||||
)
|
)
|
||||||
name = models.CharField(
|
name = models.CharField(
|
||||||
max_length=50
|
max_length=50
|
||||||
@ -1080,7 +1080,7 @@ class FrontPortTemplate(ComponentTemplateModel):
|
|||||||
device_type = models.ForeignKey(
|
device_type = models.ForeignKey(
|
||||||
to='dcim.DeviceType',
|
to='dcim.DeviceType',
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name='front_port_templates'
|
related_name='frontport_templates'
|
||||||
)
|
)
|
||||||
name = models.CharField(
|
name = models.CharField(
|
||||||
max_length=64
|
max_length=64
|
||||||
@ -1091,7 +1091,7 @@ class FrontPortTemplate(ComponentTemplateModel):
|
|||||||
rear_port = models.ForeignKey(
|
rear_port = models.ForeignKey(
|
||||||
to='dcim.RearPortTemplate',
|
to='dcim.RearPortTemplate',
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name='front_port_templates'
|
related_name='frontport_templates'
|
||||||
)
|
)
|
||||||
rear_port_position = models.PositiveSmallIntegerField(
|
rear_port_position = models.PositiveSmallIntegerField(
|
||||||
default=1,
|
default=1,
|
||||||
@ -1132,7 +1132,7 @@ class RearPortTemplate(ComponentTemplateModel):
|
|||||||
device_type = models.ForeignKey(
|
device_type = models.ForeignKey(
|
||||||
to='dcim.DeviceType',
|
to='dcim.DeviceType',
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name='rear_port_templates'
|
related_name='rearport_templates'
|
||||||
)
|
)
|
||||||
name = models.CharField(
|
name = models.CharField(
|
||||||
max_length=64
|
max_length=64
|
||||||
@ -1552,19 +1552,19 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
|
|||||||
if is_new:
|
if is_new:
|
||||||
ConsolePort.objects.bulk_create(
|
ConsolePort.objects.bulk_create(
|
||||||
[ConsolePort(device=self, name=template.name) for template in
|
[ConsolePort(device=self, name=template.name) for template in
|
||||||
self.device_type.console_port_templates.all()]
|
self.device_type.consoleport_templates.all()]
|
||||||
)
|
)
|
||||||
ConsoleServerPort.objects.bulk_create(
|
ConsoleServerPort.objects.bulk_create(
|
||||||
[ConsoleServerPort(device=self, name=template.name) for template in
|
[ConsoleServerPort(device=self, name=template.name) for template in
|
||||||
self.device_type.cs_port_templates.all()]
|
self.device_type.consoleserverport_templates.all()]
|
||||||
)
|
)
|
||||||
PowerPort.objects.bulk_create(
|
PowerPort.objects.bulk_create(
|
||||||
[PowerPort(device=self, name=template.name) for template in
|
[PowerPort(device=self, name=template.name) for template in
|
||||||
self.device_type.power_port_templates.all()]
|
self.device_type.powerport_templates.all()]
|
||||||
)
|
)
|
||||||
PowerOutlet.objects.bulk_create(
|
PowerOutlet.objects.bulk_create(
|
||||||
[PowerOutlet(device=self, name=template.name) for template in
|
[PowerOutlet(device=self, name=template.name) for template in
|
||||||
self.device_type.power_outlet_templates.all()]
|
self.device_type.poweroutlet_templates.all()]
|
||||||
)
|
)
|
||||||
Interface.objects.bulk_create(
|
Interface.objects.bulk_create(
|
||||||
[Interface(device=self, name=template.name, form_factor=template.form_factor,
|
[Interface(device=self, name=template.name, form_factor=template.form_factor,
|
||||||
@ -1576,7 +1576,7 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
|
|||||||
name=template.name,
|
name=template.name,
|
||||||
type=template.type,
|
type=template.type,
|
||||||
positions=template.positions
|
positions=template.positions
|
||||||
) for template in self.device_type.rear_port_templates.all()
|
) for template in self.device_type.rearport_templates.all()
|
||||||
])
|
])
|
||||||
FrontPort.objects.bulk_create([
|
FrontPort.objects.bulk_create([
|
||||||
FrontPort(
|
FrontPort(
|
||||||
@ -1585,7 +1585,7 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
|
|||||||
type=template.type,
|
type=template.type,
|
||||||
rear_port=RearPort.objects.get(device=self, name=template.rear_port.name),
|
rear_port=RearPort.objects.get(device=self, name=template.rear_port.name),
|
||||||
rear_port_position=template.rear_port_position,
|
rear_port_position=template.rear_port_position,
|
||||||
) for template in self.device_type.front_port_templates.all()
|
) for template in self.device_type.frontport_templates.all()
|
||||||
])
|
])
|
||||||
DeviceBay.objects.bulk_create(
|
DeviceBay.objects.bulk_create(
|
||||||
[DeviceBay(device=self, name=template.name) for template in
|
[DeviceBay(device=self, name=template.name) for template in
|
||||||
@ -2120,7 +2120,7 @@ class FrontPort(CableTermination, ComponentModel):
|
|||||||
rear_port = models.ForeignKey(
|
rear_port = models.ForeignKey(
|
||||||
to='dcim.RearPort',
|
to='dcim.RearPort',
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name='front_ports'
|
related_name='frontports'
|
||||||
)
|
)
|
||||||
rear_port_position = models.PositiveSmallIntegerField(
|
rear_port_position = models.PositiveSmallIntegerField(
|
||||||
default=1,
|
default=1,
|
||||||
@ -2546,7 +2546,7 @@ class Cable(ChangeLoggedModel):
|
|||||||
if next_cable is None:
|
if next_cable is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
far_end = next_cable.termination_b if next_cable.termination_a == peer_port else next_cable.terimation_a
|
far_end = next_cable.termination_b if next_cable.termination_a == peer_port else next_cable.termination_a
|
||||||
|
|
||||||
# Return the far side termination of the cable
|
# Return the far side termination of the cable
|
||||||
return trace_cable(far_end, position)
|
return trace_cable(far_end, position)
|
||||||
|
@ -136,7 +136,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% if devicetype.console_port_templates.exists or devicetype.power_port_templates.exists %}
|
{% if devicetype.consoleport_templates.exists or devicetype.powerport_templates.exists %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
{% include 'dcim/inc/devicetype_component_table.html' with table=consoleport_table title='Console Ports' add_url='dcim:devicetype_add_consoleport' delete_url='dcim:devicetype_delete_consoleport' %}
|
{% include 'dcim/inc/devicetype_component_table.html' with table=consoleport_table title='Console Ports' add_url='dcim:devicetype_add_consoleport' delete_url='dcim:devicetype_delete_consoleport' %}
|
||||||
@ -153,13 +153,20 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if devicetype.cs_port_templates.exists %}
|
{% if devicetype.consoleserverport_templates.exists %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
{% include 'dcim/inc/devicetype_component_table.html' with table=consoleserverport_table title='Console Server Ports' add_url='dcim:devicetype_add_consoleserverport' delete_url='dcim:devicetype_delete_consoleserverport' %}
|
{% include 'dcim/inc/devicetype_component_table.html' with table=consoleserverport_table title='Console Server Ports' add_url='dcim:devicetype_add_consoleserverport' delete_url='dcim:devicetype_delete_consoleserverport' %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if devicetype.poweroutlet_templates.exists %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
{% include 'dcim/inc/devicetype_component_table.html' with table=poweroutlet_table title='Power Outlets' add_url='dcim:devicetype_add_poweroutlet' delete_url='dcim:devicetype_delete_poweroutlet' %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% if devicetype.interface_templates.exists %}
|
{% if devicetype.interface_templates.exists %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
@ -167,14 +174,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if devicetype.power_outlet_templates.exists %}
|
{% if devicetype.frontport_templates.exists or devicetype.rearport_templates.exists %}
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-12">
|
|
||||||
{% include 'dcim/inc/devicetype_component_table.html' with table=poweroutlet_table title='Power Outlets' add_url='dcim:devicetype_add_poweroutlet' delete_url='dcim:devicetype_delete_poweroutlet' %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
{% if devicetype.front_port_templates.exists or devicetype.rear_port_templates.exists %}
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
{% include 'dcim/inc/devicetype_component_table.html' with table=front_port_table title='Front Ports' add_url='dcim:devicetype_add_frontport' delete_url='dcim:devicetype_delete_frontport' %}
|
{% include 'dcim/inc/devicetype_component_table.html' with table=front_port_table title='Front Ports' add_url='dcim:devicetype_add_frontport' delete_url='dcim:devicetype_delete_frontport' %}
|
||||||
|
Loading…
Reference in New Issue
Block a user