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
65a0d083
Commit
65a0d083
authored
Oct 31, 2014
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1963 from carljm/lazy-fields
Set up serializer fields lazily on-demand.
parents
5e1ed0aa
140f8620
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
4 deletions
+11
-4
rest_framework/serializers.py
+5
-1
tests/test_relations.py
+3
-2
tests/test_serializer.py
+3
-1
No files found.
rest_framework/serializers.py
View file @
65a0d083
...
@@ -22,6 +22,7 @@ from django.db import models
...
@@ -22,6 +22,7 @@ from django.db import models
from
django.forms
import
widgets
from
django.forms
import
widgets
from
django.utils
import
six
from
django.utils
import
six
from
django.utils.datastructures
import
SortedDict
from
django.utils.datastructures
import
SortedDict
from
django.utils.functional
import
cached_property
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.core.exceptions
import
ObjectDoesNotExist
from
rest_framework.settings
import
api_settings
from
rest_framework.settings
import
api_settings
...
@@ -197,7 +198,6 @@ class BaseSerializer(WritableField):
...
@@ -197,7 +198,6 @@ class BaseSerializer(WritableField):
self
.
init_data
=
data
self
.
init_data
=
data
self
.
init_files
=
files
self
.
init_files
=
files
self
.
object
=
instance
self
.
object
=
instance
self
.
fields
=
self
.
get_fields
()
self
.
_data
=
None
self
.
_data
=
None
self
.
_files
=
None
self
.
_files
=
None
...
@@ -212,6 +212,10 @@ class BaseSerializer(WritableField):
...
@@ -212,6 +212,10 @@ class BaseSerializer(WritableField):
#####
#####
# Methods to determine which fields to use when (de)serializing objects.
# Methods to determine which fields to use when (de)serializing objects.
@cached_property
def
fields
(
self
):
return
self
.
get_fields
()
def
get_default_fields
(
self
):
def
get_default_fields
(
self
):
"""
"""
Return the complete set of default fields for the object, as a dict.
Return the complete set of default fields for the object, as a dict.
...
...
tests/test_relations.py
View file @
65a0d083
...
@@ -102,7 +102,7 @@ class RelatedFieldSourceTests(TestCase):
...
@@ -102,7 +102,7 @@ class RelatedFieldSourceTests(TestCase):
self
.
assertEqual
(
value
,
[
'BlogPost object'
])
self
.
assertEqual
(
value
,
[
'BlogPost object'
])
# Regression for #1129
# Regression for #1129
def
test_exception_for_incorect_fk
(
self
):
def
test_exception_for_incor
r
ect_fk
(
self
):
"""
"""
Check that the exception message are correct if the source field
Check that the exception message are correct if the source field
doesn't exist.
doesn't exist.
...
@@ -123,8 +123,9 @@ class RelatedFieldSourceTests(TestCase):
...
@@ -123,8 +123,9 @@ class RelatedFieldSourceTests(TestCase):
(
serializers
.
ModelSerializer
,),
(
serializers
.
ModelSerializer
,),
attrs
attrs
)
)
serializer
=
TestSerializer
(
data
=
{
'name'
:
'foo'
})
with
self
.
assertRaises
(
AttributeError
):
with
self
.
assertRaises
(
AttributeError
):
TestSerializer
(
data
=
{
'name'
:
'foo'
})
serializer
.
fields
@unittest.skipIf
(
get_version
()
<
'1.6.0'
,
'Upstream behaviour changed in v1.6'
)
@unittest.skipIf
(
get_version
()
<
'1.6.0'
,
'Upstream behaviour changed in v1.6'
)
...
...
tests/test_serializer.py
View file @
65a0d083
...
@@ -327,7 +327,9 @@ class BasicTests(TestCase):
...
@@ -327,7 +327,9 @@ class BasicTests(TestCase):
"""
"""
Regression test for #652.
Regression test for #652.
"""
"""
self
.
assertRaises
(
AssertionError
,
PersonSerializerInvalidReadOnly
,
[])
serializer
=
PersonSerializerInvalidReadOnly
()
with
self
.
assertRaises
(
AssertionError
):
serializer
.
fields
def
test_serializer_data_is_cleared_on_save
(
self
):
def
test_serializer_data_is_cleared_on_save
(
self
):
"""
"""
...
...
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