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
c06a82d0
Commit
c06a82d0
authored
Dec 19, 2014
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Model serializer caching.
parent
62f78dfb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
1 deletions
+21
-1
rest_framework/serializers.py
+21
-1
No files found.
rest_framework/serializers.py
View file @
c06a82d0
...
@@ -682,6 +682,10 @@ def raise_errors_on_nested_writes(method_name, serializer, validated_data):
...
@@ -682,6 +682,10 @@ def raise_errors_on_nested_writes(method_name, serializer, validated_data):
)
)
MODEL_SERIALIZER_FIELDS_CACHE
=
{}
MODEL_SERIALIZER_VALIDATORS_CACHE
=
{}
class
ModelSerializer
(
Serializer
):
class
ModelSerializer
(
Serializer
):
"""
"""
A `ModelSerializer` is just a regular `Serializer`, except that:
A `ModelSerializer` is just a regular `Serializer`, except that:
...
@@ -802,6 +806,11 @@ class ModelSerializer(Serializer):
...
@@ -802,6 +806,11 @@ class ModelSerializer(Serializer):
Return the dict of field names -> field instances that should be
Return the dict of field names -> field instances that should be
used for `self.fields` when instantiating the serializer.
used for `self.fields` when instantiating the serializer.
"""
"""
cls
=
self
.
__class__
if
cls
in
MODEL_SERIALIZER_FIELDS_CACHE
:
return
copy
.
deepcopy
(
MODEL_SERIALIZER_FIELDS_CACHE
[
cls
])
declared_fields
=
copy
.
deepcopy
(
self
.
_declared_fields
)
declared_fields
=
copy
.
deepcopy
(
self
.
_declared_fields
)
model
=
getattr
(
self
.
Meta
,
'model'
)
model
=
getattr
(
self
.
Meta
,
'model'
)
depth
=
getattr
(
self
.
Meta
,
'depth'
,
0
)
depth
=
getattr
(
self
.
Meta
,
'depth'
,
0
)
...
@@ -837,6 +846,8 @@ class ModelSerializer(Serializer):
...
@@ -837,6 +846,8 @@ class ModelSerializer(Serializer):
# Add in any hidden fields.
# Add in any hidden fields.
ret
.
update
(
hidden_fields
)
ret
.
update
(
hidden_fields
)
MODEL_SERIALIZER_FIELDS_CACHE
[
cls
]
=
ret
return
ret
return
ret
# Methods for determining the set of field names to include...
# Methods for determining the set of field names to include...
...
@@ -1217,12 +1228,21 @@ class ModelSerializer(Serializer):
...
@@ -1217,12 +1228,21 @@ class ModelSerializer(Serializer):
if
validators
is
not
None
:
if
validators
is
not
None
:
return
validators
[:]
return
validators
[:]
cls
=
self
.
__class__
if
cls
in
MODEL_SERIALIZER_VALIDATORS_CACHE
:
return
MODEL_SERIALIZER_VALIDATORS_CACHE
[
cls
][:]
# Otherwise use the default set of validators.
# Otherwise use the default set of validators.
return
(
validators
=
(
self
.
get_unique_together_validators
()
+
self
.
get_unique_together_validators
()
+
self
.
get_unique_for_date_validators
()
self
.
get_unique_for_date_validators
()
)
)
MODEL_SERIALIZER_VALIDATORS_CACHE
[
cls
]
=
validators
return
validators
def
get_unique_together_validators
(
self
):
def
get_unique_together_validators
(
self
):
"""
"""
Determine a default set of validators for any unique_together contraints.
Determine a default set of validators for any unique_together contraints.
...
...
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