From b19865f88da68fc64b8035bbb37132fa632f3146 Mon Sep 17 00:00:00 2001 From: Aider Ibragimov Date: Wed, 14 Oct 2015 15:14:35 +0300 Subject: [PATCH 1/3] fix typo in adding jquery string, update docs about detail page link for AdminRenderer --- docs/api-guide/renderers.md | 9 +++++++++ .../templates/rest_framework/admin.html | 2 +- .../templates/rest_framework/admin/list.html | 15 ++++++++------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/api-guide/renderers.md b/docs/api-guide/renderers.md index 614259458..1cf924341 100644 --- a/docs/api-guide/renderers.md +++ b/docs/api-guide/renderers.md @@ -187,6 +187,15 @@ This renderer is suitable for CRUD-style web APIs that should also present a use Note that views that have nested or list serializers for their input won't work well with the `AdminRenderer`, as the HTML forms are unable to properly support them. +**Note**: To get proper links to detail page in `ListCreateAPIView` or `ListAPIView` you should implement `url` field in serializer which return correct link. For example here we use models `get_absolute_url` method: + + class AccountSerializer(serializers.ModelSerializer): + url = serializers.CharField(source='get_absolute_url', read_only=True) + + class Meta: + model = Account + + **.media_type**: `text/html` **.format**: `'.admin'` diff --git a/rest_framework/templates/rest_framework/admin.html b/rest_framework/templates/rest_framework/admin.html index e1751b21c..318a1e706 100644 --- a/rest_framework/templates/rest_framework/admin.html +++ b/rest_framework/templates/rest_framework/admin.html @@ -219,7 +219,7 @@ {% endif %} {% block script %} - + diff --git a/rest_framework/templates/rest_framework/admin/list.html b/rest_framework/templates/rest_framework/admin/list.html index a3ec21af3..048843bb7 100644 --- a/rest_framework/templates/rest_framework/admin/list.html +++ b/rest_framework/templates/rest_framework/admin/list.html @@ -7,14 +7,15 @@ {% for row in results %} {% for key, value in row.items %} - {% if key in columns %} - - {{ value|format_value }} - - {% endif %} + {% if key in columns %} + + {{ value|format_value }} + + {% endif %} {% endfor %} - - + + + {% endfor %} From 5342f2200966788f032fb35fffe4e99840e57960 Mon Sep 17 00:00:00 2001 From: Aider Ibragimov Date: Wed, 14 Oct 2015 15:54:43 +0300 Subject: [PATCH 2/3] return typo back for new pr, update docs --- docs/api-guide/renderers.md | 2 +- rest_framework/templates/rest_framework/admin.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api-guide/renderers.md b/docs/api-guide/renderers.md index 1cf924341..fb3dd312c 100644 --- a/docs/api-guide/renderers.md +++ b/docs/api-guide/renderers.md @@ -187,7 +187,7 @@ This renderer is suitable for CRUD-style web APIs that should also present a use Note that views that have nested or list serializers for their input won't work well with the `AdminRenderer`, as the HTML forms are unable to properly support them. -**Note**: To get proper links to detail page in `ListCreateAPIView` or `ListAPIView` you should implement `url` field in serializer which return correct link. For example here we use models `get_absolute_url` method: +**Note**: In ModelSerializer to get proper links to detail page in `ListCreateAPIView` or `ListAPIView` you should implement `url` field in serializer which return correct link. For example here we use models `get_absolute_url` method: class AccountSerializer(serializers.ModelSerializer): url = serializers.CharField(source='get_absolute_url', read_only=True) diff --git a/rest_framework/templates/rest_framework/admin.html b/rest_framework/templates/rest_framework/admin.html index 318a1e706..e1751b21c 100644 --- a/rest_framework/templates/rest_framework/admin.html +++ b/rest_framework/templates/rest_framework/admin.html @@ -219,7 +219,7 @@ {% endif %} {% block script %} - + From 4a6d27ccbb9f231474a7c9effe7af3e3b2265725 Mon Sep 17 00:00:00 2001 From: Aider Ibragimov Date: Wed, 14 Oct 2015 17:04:47 +0300 Subject: [PATCH 3/3] update style of the note --- docs/api-guide/renderers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api-guide/renderers.md b/docs/api-guide/renderers.md index fb3dd312c..254835c2e 100644 --- a/docs/api-guide/renderers.md +++ b/docs/api-guide/renderers.md @@ -187,7 +187,7 @@ This renderer is suitable for CRUD-style web APIs that should also present a use Note that views that have nested or list serializers for their input won't work well with the `AdminRenderer`, as the HTML forms are unable to properly support them. -**Note**: In ModelSerializer to get proper links to detail page in `ListCreateAPIView` or `ListAPIView` you should implement `url` field in serializer which return correct link. For example here we use models `get_absolute_url` method: +**Note**: The `AdminRenderer` is only able to include links to detail pages when a properly configured `URL_FIELD_NAME` (`url` by default) attribute is present in the data. For `HyperlinkedModelSerializer` this will be the case, but for `ModelSerializer` or plain `Serializer` classes you'll need to make sure to include the field explicitly. For example here we use models `get_absolute_url` method: class AccountSerializer(serializers.ModelSerializer): url = serializers.CharField(source='get_absolute_url', read_only=True)