Skip to content

Commit 9e62d1a

Browse files
committed
Fixes #6130: Improve display of assigned models in custom fields list
1 parent 696b5c8 commit 9e62d1a

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

docs/release-notes/version-2.11.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* [#6106](https://github.com/netbox-community/netbox/issues/6106) - Allow assigning a virtual interface as the parent of an existing interface
1616
* [#6107](https://github.com/netbox-community/netbox/issues/6107) - Fix rack selection field on device form
1717
* [#6110](https://github.com/netbox-community/netbox/issues/6110) - Fix handling of TemplateColumn values for table export
18+
* [#6130](https://github.com/netbox-community/netbox/issues/6130) - Improve display of assigned models in custom fields list
1819

1920
---
2021

netbox/extras/admin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from django import forms
22
from django.contrib import admin
33
from django.contrib.contenttypes.models import ContentType
4+
from django.utils.safestring import mark_safe
45

56
from utilities.forms import ContentTypeChoiceField, ContentTypeMultipleChoiceField, LaxURLField
7+
from utilities.utils import content_type_name
68
from .models import CustomField, CustomLink, ExportTemplate, JobResult, Webhook
79
from .utils import FeatureQuery
810

@@ -110,7 +112,8 @@ class CustomFieldAdmin(admin.ModelAdmin):
110112
)
111113

112114
def models(self, obj):
113-
return ', '.join([ct.name for ct in obj.content_types.all()])
115+
ct_names = [content_type_name(ct) for ct in obj.content_types.all()]
116+
return mark_safe('<br/>'.join(ct_names))
114117

115118

116119
#

netbox/utilities/forms/fields.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from django.urls import reverse
1414

1515
from utilities.choices import unpack_grouped_choices
16+
from utilities.utils import content_type_name
1617
from utilities.validators import EnhancedURLValidator
1718
from . import widgets
1819
from .constants import *
@@ -124,8 +125,7 @@ def __init__(self, queryset, *args, **kwargs):
124125

125126
def label_from_instance(self, obj):
126127
try:
127-
meta = obj.model_class()._meta
128-
return f'{meta.app_config.verbose_name} > {meta.verbose_name}'
128+
return content_type_name(obj)
129129
except AttributeError:
130130
return super().label_from_instance(obj)
131131

netbox/utilities/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,14 @@ def array_to_string(array):
296296
return ', '.join('-'.join(map(str, (g[0], g[-1])[:len(g)])) for g in group)
297297

298298

299+
def content_type_name(contenttype):
300+
"""
301+
Return a proper ContentType name.
302+
"""
303+
meta = contenttype.model_class()._meta
304+
return f'{meta.app_config.verbose_name} > {meta.verbose_name}'
305+
306+
299307
#
300308
# Fake request object
301309
#

0 commit comments

Comments
 (0)