1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Initial work on #5883

This commit is contained in:
jeremystretch
2021-10-25 14:42:20 -04:00
parent 61d2158f76
commit 82243732a1
18 changed files with 375 additions and 109 deletions

View File

@@ -15,6 +15,7 @@ from dcim.constants import *
from extras.models import ConfigContextModel
from extras.querysets import ConfigContextModelQuerySet
from extras.utils import extras_features
from netbox.config import ConfigResolver
from netbox.models import OrganizationalModel, PrimaryModel
from utilities.choices import ColorChoices
from utilities.fields import ColorField, NaturalOrderingField
@@ -815,7 +816,8 @@ class Device(PrimaryModel, ConfigContextModel):
@property
def primary_ip(self):
if settings.PREFER_IPV4 and self.primary_ip4:
config = ConfigResolver()
if config.PREFER_IPV4 and self.primary_ip4:
return self.primary_ip4
elif self.primary_ip6:
return self.primary_ip6

View File

@@ -160,18 +160,11 @@ class DeviceTable(BaseTable):
linkify=True,
verbose_name='Type'
)
if settings.PREFER_IPV4:
primary_ip = tables.Column(
linkify=True,
order_by=('primary_ip4', 'primary_ip6'),
verbose_name='IP Address'
)
else:
primary_ip = tables.Column(
linkify=True,
order_by=('primary_ip6', 'primary_ip4'),
verbose_name='IP Address'
)
primary_ip = tables.Column(
linkify=True,
order_by=('primary_ip4', 'primary_ip6'),
verbose_name='IP Address'
)
primary_ip4 = tables.Column(
linkify=True,
verbose_name='IPv4 Address'