From 1a4f48027d338f69d54a015d4d1de52b12d10cf8 Mon Sep 17 00:00:00 2001 From: mehrab Date: Tue, 1 Oct 2019 20:58:02 +0330 Subject: [PATCH] Documented templatetags.rest_framework:add_nested_class --- rest_framework/templatetags/rest_framework.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rest_framework/templatetags/rest_framework.py b/rest_framework/templatetags/rest_framework.py index 79dd953ff..c82e63f2b 100644 --- a/rest_framework/templatetags/rest_framework.py +++ b/rest_framework/templatetags/rest_framework.py @@ -283,6 +283,12 @@ def schema_links(section, sec_key=None): @register.filter def add_nested_class(value): + """ + Check if value is instance of `dict` or `list` of `dict` objects return the `nested` class + Othervise return '' (blank string) + Usage + {{ value|add_nested_class }} + """ if isinstance(value, dict): return 'class=nested' if isinstance(value, list) and any([isinstance(item, (list, dict)) for item in value]):