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
b9bff2a9
Commit
b9bff2a9
authored
Nov 02, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix issues with pk related fields in the browsable API.
parent
2dec2b9c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
2 deletions
+65
-2
README.md
+16
-0
docs/topics/release-notes.md
+10
-0
rest_framework/__init__.py
+1
-1
rest_framework/fields.py
+38
-1
No files found.
README.md
View file @
b9bff2a9
...
...
@@ -57,8 +57,24 @@ To run the tests.
# Changelog
## 2.0.2
**Date**
: 2nd Nov 2012
*
Fix issues with pk related fields in the browsable API.
## 2.0.1
**Date**
: 1st Nov 2012
*
Add support for relational fields in the browsable API.
*
Added SlugRelatedField and ManySlugRelatedField.
*
If PUT creates an instance return '201 Created', instead of '200 OK'.
## 2.0.0
**Date**
: 30th Oct 2012
*
Redesign of core components.
*
Fix
**all of the things**
.
...
...
docs/topics/release-notes.md
View file @
b9bff2a9
...
...
@@ -4,14 +4,24 @@
>
> — Eric S. Raymond, [The Cathedral and the Bazaar][cite].
## 2.0.2
**Date**
: 2nd Nov 2012
*
Fix issues with pk related fields in the browsable API.
## 2.0.1
**Date**
: 1st Nov 2012
*
Add support for relational fields in the browsable API.
*
Added SlugRelatedField and ManySlugRelatedField.
*
If PUT creates an instance return '201 Created', instead of '200 OK'.
## 2.0.0
**Date**
: 30th Oct 2012
*
**Fix all of the things.**
(Well, almost.)
*
For more information please see the
[
2.0 migration guide
][
migration
]
.
...
...
rest_framework/__init__.py
View file @
b9bff2a9
__version__
=
'2.0.
1
'
__version__
=
'2.0.
2
'
VERSION
=
__version__
# synonym
rest_framework/fields.py
View file @
b9bff2a9
...
...
@@ -230,6 +230,7 @@ class ModelField(WritableField):
##### Relational fields #####
# Not actually Writable, but subclasses may need to be.
class
RelatedField
(
WritableField
):
"""
Base class for related model fields.
...
...
@@ -240,10 +241,12 @@ class RelatedField(WritableField):
widget
=
widgets
.
Select
cache_choices
=
False
empty_label
=
None
default_read_only
=
True
# TODO: Remove this
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
queryset
=
kwargs
.
pop
(
'queryset'
,
None
)
super
(
RelatedField
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
read_only
=
self
.
default_read_only
### We need this stuff to make form choices work...
...
...
@@ -260,7 +263,7 @@ class RelatedField(WritableField):
Return a readable representation for use with eg. select widgets.
"""
desc
=
smart_unicode
(
obj
)
ident
=
s
elf
.
to_native
(
obj
)
ident
=
s
mart_unicode
(
self
.
to_native
(
obj
)
)
if
desc
==
ident
:
return
desc
return
"
%
s -
%
s"
%
(
desc
,
ident
)
...
...
@@ -353,7 +356,23 @@ class PrimaryKeyRelatedField(RelatedField):
"""
Represents a to-one relationship as a pk value.
"""
default_read_only
=
False
# TODO: Remove these field hacks...
def
prepare_value
(
self
,
obj
):
return
self
.
to_native
(
obj
.
pk
)
def
label_from_instance
(
self
,
obj
):
"""
Return a readable representation for use with eg. select widgets.
"""
desc
=
smart_unicode
(
obj
)
ident
=
smart_unicode
(
self
.
to_native
(
obj
.
pk
))
if
desc
==
ident
:
return
desc
return
"
%
s -
%
s"
%
(
desc
,
ident
)
# TODO: Possibly change this to just take `obj`, through prob less performant
def
to_native
(
self
,
pk
):
return
pk
...
...
@@ -382,6 +401,21 @@ class ManyPrimaryKeyRelatedField(ManyRelatedField):
"""
Represents a to-many relationship as a pk value.
"""
default_read_only
=
False
def
prepare_value
(
self
,
obj
):
return
self
.
to_native
(
obj
.
pk
)
def
label_from_instance
(
self
,
obj
):
"""
Return a readable representation for use with eg. select widgets.
"""
desc
=
smart_unicode
(
obj
)
ident
=
smart_unicode
(
self
.
to_native
(
obj
.
pk
))
if
desc
==
ident
:
return
desc
return
"
%
s -
%
s"
%
(
desc
,
ident
)
def
to_native
(
self
,
pk
):
return
pk
...
...
@@ -400,6 +434,8 @@ class ManyPrimaryKeyRelatedField(ManyRelatedField):
class
SlugRelatedField
(
RelatedField
):
default_read_only
=
False
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
slug_field
=
kwargs
.
pop
(
'slug_field'
,
None
)
assert
self
.
slug_field
,
'slug_field is required'
...
...
@@ -429,6 +465,7 @@ class HyperlinkedRelatedField(RelatedField):
pk_url_kwarg
=
'pk'
slug_url_kwarg
=
'slug'
slug_field
=
'slug'
default_read_only
=
False
def
__init__
(
self
,
*
args
,
**
kwargs
):
try
:
...
...
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