8000 Convert Django form decimals to Graphene decimals · graphql-python/graphene-django@aaa15c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit aaa15c8

Browse files
committed
Convert Django form decimals to Graphene decimals
1 parent caf9548 commit aaa15c8

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

graphene_django/filter/tests/test_fields.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from django.db.models import TextField, Value
66
from django.db.models.functions import Concat
77

8-
from graphene import Argument, Boolean, Field, Float, ObjectType, Schema, String
8+
from graphene import Argument, Boolean, Decimal, Field, ObjectType, Schema, String
99
from graphene.relay import Node
1010
from graphene_django import DjangoObjectType
1111
from graphene_django.forms import GlobalIDFormField, GlobalIDMultipleChoiceField
@@ -388,7 +388,7 @@ class Meta:
388388
field = DjangoFilterConnectionField(ArticleNode, filterset_class=ArticleIdFilter)
389389
max_time = field.args["max_time"]
390390
assert isinstance(max_time, Argument)
391-
assert max_time.type == Float
391+
assert max_time.type == Decimal
392392
assert max_time.description == "The maximum time"
393393

394394

graphene_django/forms/converter.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
from django import forms
22
from django.core.exceptions import ImproperlyConfigured
33

4-
from graphene import ID, Boolean, Float, Int, List, String, UUID, Date, DateTime, Time
4+
from graphene import (
5+
Boolean,
6+
Date,
7+
DateTime,
8+
Decimal,
9+
Float,
10+
ID,
11+
Int,
12+
List,
13+
String,
14+
Time,
15+
UUID,
16+
)
517

618
from .forms import GlobalIDFormField, GlobalIDMultipleChoiceField
719
from ..utils import import_single_dispatch
820

9-
1021
singledispatch = import_single_dispatch()
1122

1223

@@ -52,6 +63,10 @@ def convert_form_field_to_nullboolean(field):
5263

5364

5465
@convert_form_field.register(forms.DecimalField)
66+
def convert_field_to_decimal(field):
67+
return Decimal(description=field.help_text, required=field.required)
68+
69+
5570
@convert_form_field.register(forms.FloatField)
5671
def convert_form_field_to_float(field):
5772
return Float(description=field.help_text, required=field.required)

graphene_django/forms/tests/test_converter.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
from django import forms
22
from py.test import raises
33

4-
import graphene
54
from graphene import (
6-
String,
7-
Int,
85
Boolean,
6+
Date,
7+
DateTime,
8+
Decimal,
99
Float,
1010
ID,
11-
UUID,
11+
Int,
1212
List,
1313
NonNull,
14-
DateTime,
15-
Date,
14+
String,
1615
Time,
16+
UUID,
1717
)
1818

1919
from ..converter import convert_form_field
@@ -97,8 +97,8 @@ def test_should_float_convert_float():
9797
assert_conversion(forms.FloatField, Float)
9898

9999

100-
def test_should_decimal_convert_float():
101-
assert_conversion(forms.DecimalField, Float)
100+
def test_should_decimal_convert_decimal():
101+
assert_conversion(forms.DecimalField, Decimal)
102102

103103

104104
def test_should_multiple_choice_convert_list():

0 commit comments

Comments
 (0)
0