mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 17:08:41 -06:00
Fixes #8815: Fix display of custom object fields in table columns
This commit is contained in:
parent
cd29293dd6
commit
06781beb81
@ -159,6 +159,7 @@ Where it is desired to limit the range of available VLANs within a group, users
|
|||||||
* [#8764](https://github.com/netbox-community/netbox/issues/8764) - Correct view name resolution for dynamic form fields
|
* [#8764](https://github.com/netbox-community/netbox/issues/8764) - Correct view name resolution for dynamic form fields
|
||||||
* [#8791](https://github.com/netbox-community/netbox/issues/8791) - Fix display of form validation failures during device component creation
|
* [#8791](https://github.com/netbox-community/netbox/issues/8791) - Fix display of form validation failures during device component creation
|
||||||
* [#8792](https://github.com/netbox-community/netbox/issues/8792) - Fix creation of circuit terminations via UI
|
* [#8792](https://github.com/netbox-community/netbox/issues/8792) - Fix creation of circuit terminations via UI
|
||||||
|
* [#8815](https://github.com/netbox-community/netbox/issues/8815) - Fix display of custom object fields in table columns
|
||||||
|
|
||||||
### Other Changes
|
### Other Changes
|
||||||
|
|
||||||
|
@ -361,27 +361,35 @@ class CustomFieldColumn(tables.Column):
|
|||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _likify_item(item):
|
||||||
|
if hasattr(item, 'get_absolute_url'):
|
||||||
|
return f'<a href="{item.get_absolute_url()}">{item}</a>'
|
||||||
|
return item
|
||||||
|
|
||||||
def render(self, value):
|
def render(self, value):
|
||||||
if isinstance(value, list):
|
if self.customfield.type == CustomFieldTypeChoices.TYPE_BOOLEAN and value is True:
|
||||||
return ', '.join(v for v in value)
|
|
||||||
elif self.customfield.type == CustomFieldTypeChoices.TYPE_BOOLEAN and value is True:
|
|
||||||
return mark_safe('<i class="mdi mdi-check-bold text-success"></i>')
|
return mark_safe('<i class="mdi mdi-check-bold text-success"></i>')
|
||||||
elif self.customfield.type == CustomFieldTypeChoices.TYPE_BOOLEAN and value is False:
|
if self.customfield.type == CustomFieldTypeChoices.TYPE_BOOLEAN and value is False:
|
||||||
return mark_safe('<i class="mdi mdi-close-thick text-danger"></i>')
|
return mark_safe('<i class="mdi mdi-close-thick text-danger"></i>')
|
||||||
elif self.customfield.type == CustomFieldTypeChoices.TYPE_URL:
|
if self.customfield.type == CustomFieldTypeChoices.TYPE_URL:
|
||||||
return mark_safe(f'<a href="{value}">{value}</a>')
|
return mark_safe(f'<a href="{value}">{value}</a>')
|
||||||
|
if self.customfield.type == CustomFieldTypeChoices.TYPE_MULTISELECT:
|
||||||
|
return ', '.join(v for v in value)
|
||||||
|
if self.customfield.type == CustomFieldTypeChoices.TYPE_MULTIOBJECT:
|
||||||
|
return mark_safe(', '.join([
|
||||||
|
self._likify_item(obj) for obj in self.customfield.deserialize(value)
|
||||||
|
]))
|
||||||
if value is not None:
|
if value is not None:
|
||||||
obj = self.customfield.deserialize(value)
|
obj = self.customfield.deserialize(value)
|
||||||
if hasattr(obj, 'get_absolute_url'):
|
return mark_safe(self._likify_item(obj))
|
||||||
return mark_safe(f'<a href="{obj.get_absolute_url}">{obj}</a>')
|
|
||||||
return obj
|
|
||||||
return self.default
|
return self.default
|
||||||
|
|
||||||
def value(self, value):
|
def value(self, value):
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
return ','.join(v for v in value)
|
return ','.join(str(v) for v in self.customfield.deserialize(value))
|
||||||
if value is not None:
|
if value is not None:
|
||||||
return value
|
return self.customfield.deserialize(value)
|
||||||
return self.default
|
return self.default
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user