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
4db23cae
Commit
4db23cae
authored
Sep 22, 2014
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tweaks to DecimalField
parent
249253a1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
12 deletions
+13
-12
rest_framework/fields.py
+13
-12
tests/test_fields.py
+0
-0
No files found.
rest_framework/fields.py
View file @
4db23cae
...
@@ -521,20 +521,21 @@ class DecimalField(Field):
...
@@ -521,20 +521,21 @@ class DecimalField(Field):
return
value
return
value
def
to_representation
(
self
,
value
):
def
to_representation
(
self
,
value
):
if
isinstance
(
value
,
decimal
.
Decimal
):
if
value
in
(
None
,
''
):
context
=
decimal
.
getcontext
()
.
copy
()
return
None
context
.
prec
=
self
.
max_digits
quantized
=
value
.
quantize
(
decimal
.
Decimal
(
'.1'
)
**
self
.
decimal_places
,
context
=
context
)
if
not
self
.
coerce_to_string
:
return
quantized
return
'{0:f}'
.
format
(
quantized
)
if
not
isinstance
(
value
,
decimal
.
Decimal
):
value
=
decimal
.
Decimal
(
value
)
context
=
decimal
.
getcontext
()
.
copy
()
context
.
prec
=
self
.
max_digits
quantized
=
value
.
quantize
(
decimal
.
Decimal
(
'.1'
)
**
self
.
decimal_places
,
context
=
context
)
if
not
self
.
coerce_to_string
:
if
not
self
.
coerce_to_string
:
return
value
return
quantized
return
'
%.*
f'
%
(
self
.
max_decimal_places
,
value
)
return
'
{0:f}'
.
format
(
quantized
)
# Date & time fields...
# Date & time fields...
...
...
tests/test_fields.py
View file @
4db23cae
This diff is collapsed.
Click to expand it.
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