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
bfea7f64
Commit
bfea7f64
authored
Jan 03, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tweak behavior of hyperlinked fields that include an explicit format suffix.
parent
92ae0820
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
2 deletions
+16
-2
docs/topics/release-notes.md
+1
-1
rest_framework/relations.py
+15
-1
No files found.
docs/topics/release-notes.md
View file @
bfea7f64
...
@@ -66,7 +66,7 @@ This change will not affect user code, so long as it's following the recommended
...
@@ -66,7 +66,7 @@ This change will not affect user code, so long as it's following the recommended
*
Bugfix: Ensure read-only fields don't have model validation applied.
*
Bugfix: Ensure read-only fields don't have model validation applied.
*
Bugfix: Fix hyperlinked fields in paginated results.
*
Bugfix: Fix hyperlinked fields in paginated results.
## 2.1.9
##
#
2.1.9
**Date**
: 11th Dec 2012
**Date**
: 11th Dec 2012
...
...
rest_framework/relations.py
View file @
bfea7f64
...
@@ -407,6 +407,7 @@ class HyperlinkedIdentityField(Field):
...
@@ -407,6 +407,7 @@ class HyperlinkedIdentityField(Field):
# TODO: Make view_name mandatory, and have the
# TODO: Make view_name mandatory, and have the
# HyperlinkedModelSerializer set it on-the-fly
# HyperlinkedModelSerializer set it on-the-fly
self
.
view_name
=
kwargs
.
pop
(
'view_name'
,
None
)
self
.
view_name
=
kwargs
.
pop
(
'view_name'
,
None
)
# Optionally the format of the target hyperlink may be specified
self
.
format
=
kwargs
.
pop
(
'format'
,
None
)
self
.
format
=
kwargs
.
pop
(
'format'
,
None
)
self
.
slug_field
=
kwargs
.
pop
(
'slug_field'
,
self
.
slug_field
)
self
.
slug_field
=
kwargs
.
pop
(
'slug_field'
,
self
.
slug_field
)
...
@@ -418,9 +419,22 @@ class HyperlinkedIdentityField(Field):
...
@@ -418,9 +419,22 @@ class HyperlinkedIdentityField(Field):
def
field_to_native
(
self
,
obj
,
field_name
):
def
field_to_native
(
self
,
obj
,
field_name
):
request
=
self
.
context
.
get
(
'request'
,
None
)
request
=
self
.
context
.
get
(
'request'
,
None
)
format
=
self
.
format
or
self
.
context
.
get
(
'format'
,
None
)
format
=
self
.
context
.
get
(
'format'
,
None
)
view_name
=
self
.
view_name
or
self
.
parent
.
opts
.
view_name
view_name
=
self
.
view_name
or
self
.
parent
.
opts
.
view_name
kwargs
=
{
self
.
pk_url_kwarg
:
obj
.
pk
}
kwargs
=
{
self
.
pk_url_kwarg
:
obj
.
pk
}
# By default use whatever format is given for the current context
# unless the target is a different type to the source.
#
# Eg. Consider a HyperlinkedIdentityField pointing from a json
# representation to an html property of that representation...
#
# '/snippets/1/' should link to '/snippets/1/highlight/'
# ...but...
# '/snippets/1/.json' should link to '/snippets/1/highlight/.html'
if
format
and
self
.
format
and
self
.
format
!=
format
:
format
=
self
.
format
try
:
try
:
return
reverse
(
view_name
,
kwargs
=
kwargs
,
request
=
request
,
format
=
format
)
return
reverse
(
view_name
,
kwargs
=
kwargs
,
request
=
request
,
format
=
format
)
except
:
except
:
...
...
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