mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 04:22:01 -06:00
Fixes #6130: Improve display of assigned models in custom fields list
This commit is contained in:
parent
696b5c80a7
commit
9e62d1ad8f
@ -15,6 +15,7 @@
|
|||||||
* [#6106](https://github.com/netbox-community/netbox/issues/6106) - Allow assigning a virtual interface as the parent of an existing interface
|
* [#6106](https://github.com/netbox-community/netbox/issues/6106) - Allow assigning a virtual interface as the parent of an existing interface
|
||||||
* [#6107](https://github.com/netbox-community/netbox/issues/6107) - Fix rack selection field on device form
|
* [#6107](https://github.com/netbox-community/netbox/issues/6107) - Fix rack selection field on device form
|
||||||
* [#6110](https://github.com/netbox-community/netbox/issues/6110) - Fix handling of TemplateColumn values for table export
|
* [#6110](https://github.com/netbox-community/netbox/issues/6110) - Fix handling of TemplateColumn values for table export
|
||||||
|
* [#6130](https://github.com/netbox-community/netbox/issues/6130) - Improve display of assigned models in custom fields list
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
from utilities.forms import ContentTypeChoiceField, ContentTypeMultipleChoiceField, LaxURLField
|
from utilities.forms import ContentTypeChoiceField, ContentTypeMultipleChoiceField, LaxURLField
|
||||||
|
from utilities.utils import content_type_name
|
||||||
from .models import CustomField, CustomLink, ExportTemplate, JobResult, Webhook
|
from .models import CustomField, CustomLink, ExportTemplate, JobResult, Webhook
|
||||||
from .utils import FeatureQuery
|
from .utils import FeatureQuery
|
||||||
|
|
||||||
@ -110,7 +112,8 @@ class CustomFieldAdmin(admin.ModelAdmin):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def models(self, obj):
|
def models(self, obj):
|
||||||
return ', '.join([ct.name for ct in obj.content_types.all()])
|
ct_names = [content_type_name(ct) for ct in obj.content_types.all()]
|
||||||
|
return mark_safe('<br/>'.join(ct_names))
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -13,6 +13,7 @@ from django.forms import BoundField
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from utilities.choices import unpack_grouped_choices
|
from utilities.choices import unpack_grouped_choices
|
||||||
|
from utilities.utils import content_type_name
|
||||||
from utilities.validators import EnhancedURLValidator
|
from utilities.validators import EnhancedURLValidator
|
||||||
from . import widgets
|
from . import widgets
|
||||||
from .constants import *
|
from .constants import *
|
||||||
@ -124,8 +125,7 @@ class ContentTypeChoiceMixin:
|
|||||||
|
|
||||||
def label_from_instance(self, obj):
|
def label_from_instance(self, obj):
|
||||||
try:
|
try:
|
||||||
meta = obj.model_class()._meta
|
return content_type_name(obj)
|
||||||
return f'{meta.app_config.verbose_name} > {meta.verbose_name}'
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return super().label_from_instance(obj)
|
return super().label_from_instance(obj)
|
||||||
|
|
||||||
|
@ -296,6 +296,14 @@ def array_to_string(array):
|
|||||||
return ', '.join('-'.join(map(str, (g[0], g[-1])[:len(g)])) for g in group)
|
return ', '.join('-'.join(map(str, (g[0], g[-1])[:len(g)])) for g in group)
|
||||||
|
|
||||||
|
|
||||||
|
def content_type_name(contenttype):
|
||||||
|
"""
|
||||||
|
Return a proper ContentType name.
|
||||||
|
"""
|
||||||
|
meta = contenttype.model_class()._meta
|
||||||
|
return f'{meta.app_config.verbose_name} > {meta.verbose_name}'
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Fake request object
|
# Fake request object
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user