Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
66a6ffaf
Commit
66a6ffaf
authored
Feb 19, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix typos.
parent
61860688
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
10 deletions
+10
-10
docs/api-guide/relations.md
+10
-10
No files found.
docs/api-guide/relations.md
View file @
66a6ffaf
...
...
@@ -43,7 +43,7 @@ In order to explain the various types of relational fields, we'll use a couple o
For example, the following serializer.
class AlbumSerializer(serializer.ModelSerializer):
class AlbumSerializer(serializer
s
.ModelSerializer):
tracks = RelatedField(many=True)
class Meta:
...
...
@@ -75,7 +75,7 @@ This field is read only.
For example, the following serializer:
class AlbumSerializer(serializer.ModelSerializer):
class AlbumSerializer(serializer
s
.ModelSerializer):
tracks = PrimaryKeyRelatedField(many=True, read_only=True)
class Meta:
...
...
@@ -109,7 +109,7 @@ By default this field is read-write, although you can change this behavior using
For example, the following serializer:
class AlbumSerializer(serializer.ModelSerializer):
class AlbumSerializer(serializer
s
.ModelSerializer):
tracks = HyperlinkedRelatedField(many=True, read_only=True,
view_name='track-detail')
...
...
@@ -149,7 +149,7 @@ By default this field is read-write, although you can change this behavior using
For example, the following serializer:
class AlbumSerializer(serializer.ModelSerializer):
class AlbumSerializer(serializer
s
.ModelSerializer):
tracks = SlugRelatedField(many=True, read_only=True, slug_field='title')
class Meta:
...
...
@@ -223,12 +223,12 @@ Note that nested relationships are currently read-only. For read-write relation
For example, the following serializer:
class TrackSerializer(serializer.ModelSerializer):
class TrackSerializer(serializer
s
.ModelSerializer):
class Meta:
model = Track
fields = ('order', 'title')
class AlbumSerializer(serializer.ModelSerializer):
class AlbumSerializer(serializer
s
.ModelSerializer):
tracks = TrackSerializer(many=True)
class Meta:
...
...
@@ -265,7 +265,7 @@ For, example, we could define a relational field, to serialize a track to a cust
duration = time.strftime('%M:%S', time.gmtime(value.duration))
return 'Track %d: %s (%s)' % (value.order, value.name, duration)
class AlbumSerializer(serializer.ModelSerializer):
class AlbumSerializer(serializer
s
.ModelSerializer):
tracks = TrackListingField(many=True)
class Meta:
...
...
@@ -295,13 +295,13 @@ Note that reverse relationships are not automatically generated by the `ModelSer
*
*The
following will not work:**
class AlbumSerializer(serializer.ModelSerializer)
:
class AlbumSerializer(serializer
s
.ModelSerializer)
:
class Meta
:
fields = ('tracks', ...)
Instead, you must explicitly add it to the serializer. For example
:
class AlbumSerializer(serializer.ModelSerializer)
:
class AlbumSerializer(serializer
s
.ModelSerializer)
:
tracks = serializers.PrimaryKeyRelationship(many=True)
...
...
...
@@ -315,7 +315,7 @@ The best way to ensure this is typically to make sure that the relationship on t
Alternatively, you can use the `source` argument on the serializer field, to use a different accessor attribute than the field name. For example.
class AlbumSerializer(serializer.ModelSerializer)
:
class AlbumSerializer(serializer
s
.ModelSerializer)
:
tracks = serializers.PrimaryKeyRelationship(many=True, source='track_set')
See the Django documentation on [reverse relationships][reverse-relationships] for more details.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment