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
c98ac3e8
Commit
c98ac3e8
authored
May 29, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added get_url hook to HyperlinkedIdentityField in line with HyperlinedRelatedField. Closes #883
parent
85fe7197
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
1 deletions
+20
-1
rest_framework/relations.py
+20
-1
No files found.
rest_framework/relations.py
View file @
c98ac3e8
...
@@ -537,6 +537,25 @@ class HyperlinkedIdentityField(Field):
...
@@ -537,6 +537,25 @@ class HyperlinkedIdentityField(Field):
if
format
and
self
.
format
and
self
.
format
!=
format
:
if
format
and
self
.
format
and
self
.
format
!=
format
:
format
=
self
.
format
format
=
self
.
format
# Return the hyperlink, or error if incorrectly configured.
try
:
return
self
.
get_url
(
obj
,
view_name
,
request
,
format
)
except
NoReverseMatch
:
msg
=
(
'Could not resolve URL for hyperlinked relationship using '
'view name "
%
s". You may have failed to include the related '
'model in your API, or incorrectly configured the '
'`lookup_field` attribute on this field.'
)
raise
Exception
(
msg
%
view_name
)
def
get_url
(
self
,
obj
,
view_name
,
request
,
format
):
"""
Given an object, return the URL that hyperlinks to the object.
May raise a `NoReverseMatch` if the `view_name` and `lookup_field`
attributes are not configured to correctly match the URL conf.
"""
lookup_field
=
getattr
(
obj
,
self
.
lookup_field
)
lookup_field
=
getattr
(
obj
,
self
.
lookup_field
)
kwargs
=
{
self
.
lookup_field
:
lookup_field
}
kwargs
=
{
self
.
lookup_field
:
lookup_field
}
try
:
try
:
...
@@ -562,7 +581,7 @@ class HyperlinkedIdentityField(Field):
...
@@ -562,7 +581,7 @@ class HyperlinkedIdentityField(Field):
except
NoReverseMatch
:
except
NoReverseMatch
:
pass
pass
raise
Exception
(
'Could not resolve URL for field using view name "
%
s"'
%
view_name
)
raise
NoReverseMatch
(
)
### Old-style many classes for backwards compat
### Old-style many classes for backwards compat
...
...
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