mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 12:12:53 -06:00
Introduce a template filter for getattr()
This commit is contained in:
parent
8f7d416aa5
commit
501276817e
@ -22,6 +22,7 @@ __all__ = (
|
|||||||
'content_type',
|
'content_type',
|
||||||
'content_type_id',
|
'content_type_id',
|
||||||
'fgcolor',
|
'fgcolor',
|
||||||
|
'getattr_',
|
||||||
'isodate',
|
'isodate',
|
||||||
'isodatetime',
|
'isodatetime',
|
||||||
'isotime',
|
'isotime',
|
||||||
@ -88,6 +89,14 @@ def fgcolor(value, dark='000000', light='ffffff'):
|
|||||||
return f'#{foreground_color(value, dark, light)}'
|
return f'#{foreground_color(value, dark, light)}'
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter('getattr')
|
||||||
|
def getattr_(instance, name):
|
||||||
|
"""
|
||||||
|
Call getattr() on the object for the specified attribute.
|
||||||
|
"""
|
||||||
|
return getattr(instance, name, None)
|
||||||
|
|
||||||
|
|
||||||
@register.filter()
|
@register.filter()
|
||||||
def meta(model, attr):
|
def meta(model, attr):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user