mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-13 16:47:34 -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_id',
|
||||
'fgcolor',
|
||||
'getattr_',
|
||||
'isodate',
|
||||
'isodatetime',
|
||||
'isotime',
|
||||
@ -88,6 +89,14 @@ def fgcolor(value, dark='000000', light='ffffff'):
|
||||
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()
|
||||
def meta(model, attr):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user