diff --git a/rest_framework/static/rest_framework/css/default.css b/rest_framework/static/rest_framework/css/default.css index ede54bd17..7e33aee32 100644 --- a/rest_framework/static/rest_framework/css/default.css +++ b/rest_framework/static/rest_framework/css/default.css @@ -33,6 +33,14 @@ h2, h3 { margin-right: 1em; } +td.nested { + padding: 0 !important; +} + +td.nested > table { + margin: 0; +} + form select, form input, form textarea { width: 90%; } diff --git a/rest_framework/templates/rest_framework/admin/dict_value.html b/rest_framework/templates/rest_framework/admin/dict_value.html new file mode 100644 index 000000000..e69de29bb diff --git a/rest_framework/templates/rest_framework/admin/list.html b/rest_framework/templates/rest_framework/admin/list.html index 6b72442cf..e8c547a6c 100644 --- a/rest_framework/templates/rest_framework/admin/list.html +++ b/rest_framework/templates/rest_framework/admin/list.html @@ -8,7 +8,7 @@ {% for key, value in row.items %} {% if key in columns %} - + {% if key in linked %}{% endif %} {{ value|format_value }} {% if key in linked %}{% endif %} diff --git a/rest_framework/templates/rest_framework/admin/list_value.html b/rest_framework/templates/rest_framework/admin/list_value.html new file mode 100644 index 000000000..267bbaa39 --- /dev/null +++ b/rest_framework/templates/rest_framework/admin/list_value.html @@ -0,0 +1,11 @@ +{% load rest_framework %} + + + {% for item in value %} + + + + + {% endfor %} + +
{{ forloop.counter0 }}{{ item|format_value }}
diff --git a/rest_framework/templatetags/rest_framework.py b/rest_framework/templatetags/rest_framework.py index c0431b3d2..ef7958eb3 100644 --- a/rest_framework/templatetags/rest_framework.py +++ b/rest_framework/templatetags/rest_framework.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals, absolute_import from django import template from django.core.urlresolvers import reverse, NoReverseMatch +from django.template import loader, Context from django.utils import six from django.utils.encoding import iri_to_uri, force_text from django.utils.html import escape @@ -110,9 +111,13 @@ def format_value(value): if isinstance(value, (int, float, decimal.Decimal, bool, type(None))): return mark_safe('%s' % value) elif isinstance(value, list): - return '' + template = loader.get_template('rest_framework/admin/list_value.html') + context = Context({'value': value}) + return template.render(context) elif isinstance(value, dict): - return '' + template = loader.get_template('rest_framework/admin/dict_value.html') + context = Context({'value': value}) + return template.render(context) elif isinstance(value, six.string_types): if ( (value.startswith('http:') or value.startswith('https:')) and not @@ -124,6 +129,12 @@ def format_value(value): return six.text_type(value) +@register.filter +def add_nested_class(value): + if isinstance(value, (list, dict)): + return 'class=nested' + return '' + # Bunch of stuff cloned from urlize TRAILING_PUNCTUATION = ['.', ',', ':', ';', '.)', '"', "']", "'}", "'"]