Skip to content

Commit 94b8d36

Browse files
committed
Introduce ContentTypesColumn for custom field and webhook tables
1 parent 58203db commit 94b8d36

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

netbox/extras/models/customfields.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class CustomField(ChangeLoggedModel):
3535
content_types = models.ManyToManyField(
3636
to=ContentType,
3737
related_name='custom_fields',
38-
verbose_name='Object(s)',
3938
limit_choices_to=FeatureQuery('custom_fields'),
4039
help_text='The object(s) to which this field applies.'
4140
)

netbox/extras/tables.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from django.conf import settings
33

44
from utilities.tables import (
5-
BaseTable, BooleanColumn, ButtonsColumn, ChoiceFieldColumn, ColorColumn, ContentTypeColumn, ToggleColumn,
5+
BaseTable, BooleanColumn, ButtonsColumn, ChoiceFieldColumn, ColorColumn, ContentTypeColumn, ContentTypesColumn,
6+
ToggleColumn,
67
)
78
from .models import *
89

@@ -37,14 +38,16 @@ class CustomFieldTable(BaseTable):
3738
name = tables.Column(
3839
linkify=True
3940
)
41+
content_types = ContentTypesColumn()
4042
required = BooleanColumn()
4143

4244
class Meta(BaseTable.Meta):
4345
model = CustomField
4446
fields = (
45-
'pk', 'name', 'label', 'type', 'required', 'weight', 'default', 'description', 'filter_logic', 'choices',
47+
'pk', 'name', 'content_types', 'label', 'type', 'required', 'weight', 'default', 'description',
48+
'filter_logic', 'choices',
4649
)
47-
default_columns = ('pk', 'name', 'label', 'type', 'required', 'description')
50+
default_columns = ('pk', 'name', 'content_types', 'label', 'type', 'required', 'description')
4851

4952

5053
#
@@ -98,6 +101,7 @@ class WebhookTable(BaseTable):
98101
name = tables.Column(
99102
linkify=True
100103
)
104+
content_types = ContentTypesColumn()
101105
enabled = BooleanColumn()
102106
type_create = BooleanColumn()
103107
type_update = BooleanColumn()
@@ -106,11 +110,12 @@ class WebhookTable(BaseTable):
106110
class Meta(BaseTable.Meta):
107111
model = Webhook
108112
fields = (
109-
'pk', 'name', 'enabled', 'type_create', 'type_update', 'type_delete', 'http_method', 'payload_url',
110-
'secret', 'ssl_validation', 'ca_file_path',
113+
'pk', 'name', 'content_types', 'enabled', 'type_create', 'type_update', 'type_delete', 'http_method',
114+
'payload_url', 'secret', 'ssl_validation', 'ca_file_path',
111115
)
112116
default_columns = (
113-
'pk', 'name', 'enabled', 'type_create', 'type_update', 'type_delete', 'http_method', 'payload_url',
117+
'pk', 'name', 'content_types', 'enabled', 'type_create', 'type_update', 'type_delete', 'http_method',
118+
'payload_url',
114119
)
115120

116121

netbox/utilities/tables.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from django_tables2.utils import Accessor
1313

1414
from extras.models import CustomField
15+
from extras.utils import FeatureQuery
16+
from .utils import content_type_name
1517
from .paginator import EnhancedPaginator, get_paginate_count
1618

1719

@@ -235,12 +237,20 @@ class ContentTypeColumn(tables.Column):
235237
Display a ContentType instance.
236238
"""
237239
def render(self, value):
238-
return value.name[0].upper() + value.name[1:]
240+
return content_type_name(value)
239241

240242
def value(self, value):
241243
return f"{value.app_label}.{value.model}"
242244

243245

246+
class ContentTypesColumn(tables.ManyToManyColumn):
247+
"""
248+
Display a list of ContentType instances.
249+
"""
250+
def transform(self, obj):
251+
return content_type_name(obj)
252+
253+
244254
class ColorColumn(tables.Column):
245255
"""
246256
Display a color (#RRGGBB).

0 commit comments

Comments
 (0)