1 from django import template

2

3 register = template.Library()

4

5

6@register.filter

7 def verbose_name(obj):

8 if hasattr(obj, "_meta"):

9 return obj._meta.verbose_name

10 return str(obj)

11

12

13@register.filter

14 def url_name(model, action):

15 app_label = model._meta.app_label

16 model_name = model._meta.model_name

17 return f"{app_label}:{model_name}-{action}"

18

19

20@register.filter

21 def mask(value):

22 return "********"

23

24

25@register.filter(name="add_class")

26 def add_class(field, css_classes):

27 return field.as_widget(attrs={"class": css_classes})