Fix typos.

This commit is contained in:
Tom Christie 2013-02-19 17:09:28 +00:00
parent 618606888a
commit 66a6ffaf95

View File

@ -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(serializers.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(serializers.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(serializers.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(serializers.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(serializers.ModelSerializer):
class Meta:
model = Track
fields = ('order', 'title')
class AlbumSerializer(serializer.ModelSerializer):
class AlbumSerializer(serializers.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(serializers.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(serializers.ModelSerializer):
class Meta:
fields = ('tracks', ...)
Instead, you must explicitly add it to the serializer. For example:
class AlbumSerializer(serializer.ModelSerializer):
class AlbumSerializer(serializers.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(serializers.ModelSerializer):
tracks = serializers.PrimaryKeyRelationship(many=True, source='track_set')
See the Django documentation on [reverse relationships][reverse-relationships] for more details.