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
7df11078
Commit
7df11078
authored
Sep 17, 2015
by
Yiyo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved Serializer relations docs
parent
8cae462b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
docs/api-guide/relations.md
+6
-4
No files found.
docs/api-guide/relations.md
View file @
7df11078
...
...
@@ -255,7 +255,7 @@ For example, the following serializer:
class TrackSerializer(serializers.ModelSerializer):
class Meta:
model = Track
fields = ('order', 'title')
fields = ('order', 'title'
, 'duration'
)
class AlbumSerializer(serializers.ModelSerializer):
tracks = TrackSerializer(many=True, read_only=True)
...
...
@@ -293,7 +293,7 @@ Be default nested serializers are read-only. If you want to to support write-ope
class TrackSerializer(serializers.ModelSerializer):
class Meta:
model = Track
fields = ('order', 'title')
fields = ('order', 'title'
, 'duration'
)
class AlbumSerializer(serializers.ModelSerializer):
tracks = TrackSerializer(many=True)
...
...
@@ -405,13 +405,15 @@ In this case we'd need to override `HyperlinkedRelatedField` to get the behavior
def get_url(self, obj, view_name, request, format)
:
url_kwargs = {
'organization_slug'
:
obj.organization.slug,
'customer_pk'
:
obj.pk
}
'customer_pk'
:
obj.pk
}
return reverse(view_name, url_kwargs, request=request, format=format)
def get_object(self, view_name, view_args, view_kwargs)
:
lookup_kwargs = {
'organization__slug'
:
view_kwargs['organization_slug'],
'pk'
:
view_kwargs['customer_pk']
}
'pk'
:
view_kwargs['customer_pk']
}
return self.get_queryset().get(**lookup_kwargs)
Note that if you wanted to use this style together with the generic views then you'd also need to override `.get_object` on the view in order to get the correct lookup behavior.
...
...
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