diff --git a/netbox/dcim/tables.py b/netbox/dcim/tables.py
index 0c88852f0..0ab1d594c 100644
--- a/netbox/dcim/tables.py
+++ b/netbox/dcim/tables.py
@@ -29,7 +29,8 @@ SITE_REGION_LINK = """
"""
COLOR_LABEL = """
-
+{% load helpers %}
+
"""
DEVICE_LINK = """
diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py
index e7bc40846..11fa789ec 100644
--- a/netbox/utilities/templatetags/helpers.py
+++ b/netbox/utilities/templatetags/helpers.py
@@ -1,11 +1,13 @@
import datetime
import json
+import re
from django import template
from django.utils.safestring import mark_safe
from markdown import markdown
from utilities.forms import unpack_grouped_choices
+from utilities.utils import foreground_color
register = template.Library()
@@ -152,6 +154,17 @@ def tzoffset(value):
return datetime.datetime.now(value).strftime('%z')
+@register.filter()
+def fgcolor(value):
+ """
+ Return black (#000000) or white (#ffffff) given an arbitrary background color in RRGGBB format.
+ """
+ value = value.lower().strip('#')
+ if not re.match('^[0-9a-f]{6}$', value):
+ return ''
+ return '#{}'.format(foreground_color(value))
+
+
#
# Tags
#