Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add display property to Prefix model #6190

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/6190.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `display` property to Prefix to display namespace along with the prefix to allow differentiation of prefixes in a UI selector
4 changes: 4 additions & 0 deletions nautobot/ipam/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ def __init__(self, *args, **kwargs):
def __str__(self):
return str(self.prefix)

@property
def display(self):
return f"{self.prefix}: {self.namespace}"

def _deconstruct_prefix(self, prefix):
if prefix:
if isinstance(prefix, str):
Expand Down
11 changes: 11 additions & 0 deletions nautobot/ipam/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,17 @@ def test_list_available_prefixes(self):
for i, p in enumerate(response.data):
self.assertEqual(p["prefix"], str(available_prefixes[i]))

def test_prefix_display_value(self):
"""
Test that the `display` field is correctly populated.
"""
url = reverse("ipam-api:prefix-list")
self.add_permissions("ipam.view_prefix")

response = self.client.get(f"{url}?depth=1", **self.header)
for p in response.data["results"]:
self.assertEqual(p["display"], f'{p["prefix"]}: {p["namespace"]["name"]}')

def test_create_single_available_prefix(self):
"""
Test retrieval of the first available prefix within a parent prefix.
Expand Down
Loading