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
183d3ec6
Commit
183d3ec6
authored
Feb 28, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move ModelSerializer field_mapping into an attribute for easier overriding.
parent
02ee6e5b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
21 deletions
+22
-21
rest_framework/serializers.py
+22
-21
No files found.
rest_framework/serializers.py
View file @
183d3ec6
...
...
@@ -418,6 +418,27 @@ class ModelSerializer(Serializer):
"""
_options_class
=
ModelSerializerOptions
field_mapping
=
{
models
.
AutoField
:
IntegerField
,
models
.
FloatField
:
FloatField
,
models
.
IntegerField
:
IntegerField
,
models
.
PositiveIntegerField
:
IntegerField
,
models
.
SmallIntegerField
:
IntegerField
,
models
.
PositiveSmallIntegerField
:
IntegerField
,
models
.
DateTimeField
:
DateTimeField
,
models
.
DateField
:
DateField
,
models
.
TimeField
:
TimeField
,
models
.
EmailField
:
EmailField
,
models
.
CharField
:
CharField
,
models
.
URLField
:
URLField
,
models
.
SlugField
:
SlugField
,
models
.
TextField
:
CharField
,
models
.
CommaSeparatedIntegerField
:
CharField
,
models
.
BooleanField
:
BooleanField
,
models
.
FileField
:
FileField
,
models
.
ImageField
:
ImageField
,
}
def
get_default_fields
(
self
):
"""
Return all the fields that should be serialized for the model.
...
...
@@ -515,28 +536,8 @@ class ModelSerializer(Serializer):
kwargs
[
'choices'
]
=
model_field
.
flatchoices
return
ChoiceField
(
**
kwargs
)
field_mapping
=
{
models
.
AutoField
:
IntegerField
,
models
.
FloatField
:
FloatField
,
models
.
IntegerField
:
IntegerField
,
models
.
PositiveIntegerField
:
IntegerField
,
models
.
SmallIntegerField
:
IntegerField
,
models
.
PositiveSmallIntegerField
:
IntegerField
,
models
.
DateTimeField
:
DateTimeField
,
models
.
DateField
:
DateField
,
models
.
TimeField
:
TimeField
,
models
.
EmailField
:
EmailField
,
models
.
CharField
:
CharField
,
models
.
URLField
:
URLField
,
models
.
SlugField
:
SlugField
,
models
.
TextField
:
CharField
,
models
.
CommaSeparatedIntegerField
:
CharField
,
models
.
BooleanField
:
BooleanField
,
models
.
FileField
:
FileField
,
models
.
ImageField
:
ImageField
,
}
try
:
return
field_mapping
[
model_field
.
__class__
](
**
kwargs
)
return
self
.
field_mapping
[
model_field
.
__class__
](
**
kwargs
)
except
KeyError
:
return
ModelField
(
model_field
=
model_field
,
**
kwargs
)
...
...
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