aboutsummaryrefslogtreecommitdiffstats
path: root/docs/api-guide
diff options
context:
space:
mode:
Diffstat (limited to 'docs/api-guide')
-rw-r--r--docs/api-guide/filtering.md4
-rw-r--r--docs/api-guide/relations.md14
-rw-r--r--docs/api-guide/serializers.md16
-rw-r--r--docs/api-guide/throttling.md2
4 files changed, 25 insertions, 11 deletions
diff --git a/docs/api-guide/filtering.md b/docs/api-guide/filtering.md
index 859e8d52..784aa585 100644
--- a/docs/api-guide/filtering.md
+++ b/docs/api-guide/filtering.md
@@ -195,9 +195,9 @@ For more details on using filter sets see the [django-filter documentation][djan
## SearchFilter
-The `SearchFilterBackend` class supports simple single query parameter based searching, and is based on the [Django admin's search functionality][search-django-admin].
+The `SearchFilter` class supports simple single query parameter based searching, and is based on the [Django admin's search functionality][search-django-admin].
-The `SearchFilterBackend` class will only be applied if the view has a `search_fields` attribute set. The `search_fields` attribute should be a list of names of text type fields on the model, such as `CharField` or `TextField`.
+The `SearchFilter` class will only be applied if the view has a `search_fields` attribute set. The `search_fields` attribute should be a list of names of text type fields on the model, such as `CharField` or `TextField`.
class UserListView(generics.ListAPIView):
queryset = User.objects.all()
diff --git a/docs/api-guide/relations.md b/docs/api-guide/relations.md
index 5ec4b22f..b9d96b5e 100644
--- a/docs/api-guide/relations.md
+++ b/docs/api-guide/relations.md
@@ -54,7 +54,7 @@ Would serialize to the following representation.
{
'album_name': 'Things We Lost In The Fire',
- 'artist': 'Low'
+ 'artist': 'Low',
'tracks': [
'1: Sunflower',
'2: Whitetail',
@@ -86,7 +86,7 @@ Would serialize to a representation like this:
{
'album_name': 'The Roots',
- 'artist': 'Undun'
+ 'artist': 'Undun',
'tracks': [
89,
90,
@@ -121,7 +121,7 @@ Would serialize to a representation like this:
{
'album_name': 'Graceland',
- 'artist': 'Paul Simon'
+ 'artist': 'Paul Simon',
'tracks': [
'http://www.example.com/api/tracks/45/',
'http://www.example.com/api/tracks/46/',
@@ -159,7 +159,7 @@ Would serialize to a representation like this:
{
'album_name': 'Dear John',
- 'artist': 'Loney Dear'
+ 'artist': 'Loney Dear',
'tracks': [
'Airport Surroundings',
'Everything Turns to You',
@@ -194,7 +194,7 @@ Would serialize to a representation like this:
{
'album_name': 'The Eraser',
- 'artist': 'Thom Yorke'
+ 'artist': 'Thom Yorke',
'track_listing': 'http://www.example.com/api/track_list/12/',
}
@@ -234,7 +234,7 @@ Would serialize to a nested representation like this:
{
'album_name': 'The Grey Album',
- 'artist': 'Danger Mouse'
+ 'artist': 'Danger Mouse',
'tracks': [
{'order': 1, 'title': 'Public Service Announcement'},
{'order': 2, 'title': 'What More Can I Say'},
@@ -271,7 +271,7 @@ This custom field would then serialize to the following representation.
{
'album_name': 'Sometimes I Wish We Were an Eagle',
- 'artist': 'Bill Callahan'
+ 'artist': 'Bill Callahan',
'tracks': [
'Track 1: Jim Cain (04:39)',
'Track 2: Eid Ma Clack Shaw (04:19)',
diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md
index a3cd1d6a..4c3fb9d3 100644
--- a/docs/api-guide/serializers.md
+++ b/docs/api-guide/serializers.md
@@ -67,6 +67,21 @@ At this point we've translated the model instance into Python native datatypes.
json
# '{"email": "leila@example.com", "content": "foo bar", "created": "2012-08-22T16:20:09.822"}'
+### Customizing field representation
+
+Sometimes when serializing objects, you may not want to represent everything exactly the way it is in your model.
+
+If you need to customize the serialized value of a particular field, you can do this by creating a `transform_<fieldname>` method. For example if you needed to render some markdown from a text field:
+
+ description = serializers.TextField()
+ description_html = serializers.TextField(source='description', read_only=True)
+
+ def transform_description_html(self, obj, value):
+ from django.contrib.markup.templatetags.markup import markdown
+ return markdown(value)
+
+These methods are essentially the reverse of `validate_<fieldname>` (see *Validation* below.)
+
## Deserializing objects
Deserialization is similar. First we parse a stream into Python native datatypes...
@@ -84,7 +99,6 @@ Deserialization is similar. First we parse a stream into Python native datatype
# True
serializer.object
# <Comment object at 0x10633b2d0>
- >>> serializer.deserialize('json', stream)
When deserializing data, we can either create a new instance, or update an existing instance.
diff --git a/docs/api-guide/throttling.md b/docs/api-guide/throttling.md
index cc469217..fc1525df 100644
--- a/docs/api-guide/throttling.md
+++ b/docs/api-guide/throttling.md
@@ -59,7 +59,7 @@ using the `APIView` class based views.
Or, if you're using the `@api_view` decorator with function based views.
@api_view('GET')
- @throttle_classes(UserRateThrottle)
+ @throttle_classes([UserRateThrottle])
def example_view(request, format=None):
content = {
'status': 'request was permitted'