Parcourir la source

Added fitlers to return the verbose model name of an object

Jeremy Stretch il y a 7 ans
Parent
commit
e945aafd7b
1 fichiers modifiés avec 16 ajouts et 0 suppressions
  1. 16 0
      netbox/utilities/templatetags/helpers.py

+ 16 - 0
netbox/utilities/templatetags/helpers.py

@@ -47,6 +47,22 @@ def gfm(value):
 
 
 @register.filter()
+def model_name(obj):
+    """
+    Return the name of the model of the given object
+    """
+    return obj._meta.verbose_name
+
+
+@register.filter()
+def model_name_plural(obj):
+    """
+    Return the plural name of the model of the given object
+    """
+    return obj._meta.verbose_name_plural
+
+
+@register.filter()
 def contains(value, arg):
     """
     Test whether a value contains any of a given set of strings. `arg` should be a comma-separated list of strings.