mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
* Closes #14173: Enable plugins to register columns on core tables * Support translation for column name * Document new registry store
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
from netbox.registry import registry
|
||||
|
||||
__all__ = (
|
||||
'get_table_ordering',
|
||||
'linkify_phone',
|
||||
'register_table_column'
|
||||
)
|
||||
|
||||
|
||||
@ -26,3 +29,19 @@ def linkify_phone(value):
|
||||
if value is None:
|
||||
return None
|
||||
return f"tel:{value}"
|
||||
|
||||
|
||||
def register_table_column(column, name, *tables):
|
||||
"""
|
||||
Register a custom column for use on one or more tables.
|
||||
|
||||
Args:
|
||||
column: The column instance to register
|
||||
name: The name of the table column
|
||||
tables: One or more table classes
|
||||
"""
|
||||
for table in tables:
|
||||
reg = registry['tables'][table]
|
||||
if name in reg:
|
||||
raise ValueError(f"A column named {name} is already defined for table {table.__name__}")
|
||||
reg[name] = column
|
||||
|
Reference in New Issue
Block a user