mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-22 01:27:01 +03:00
improvement: convert decimal field to graphene decimal (#1083)
This commit is contained in:
parent
e559a42374
commit
2d0b9ddd42
|
@ -18,6 +18,7 @@ from graphene import (
|
|||
DateTime,
|
||||
Date,
|
||||
Time,
|
||||
Decimal,
|
||||
)
|
||||
from graphene.types.json import JSONString
|
||||
from graphene.utils.str_converters import to_camel_case
|
||||
|
@ -160,6 +161,10 @@ def convert_field_to_boolean(field, registry=None):
|
|||
|
||||
|
||||
@convert_django_field.register(models.DecimalField)
|
||||
def convert_field_to_decimal(field, registry=None):
|
||||
return Decimal(description=field.help_text, required=not field.null)
|
||||
|
||||
|
||||
@convert_django_field.register(models.FloatField)
|
||||
@convert_django_field.register(models.DurationField)
|
||||
def convert_field_to_float(field, registry=None):
|
||||
|
|
|
@ -242,6 +242,10 @@ def test_should_float_convert_float():
|
|||
assert_conversion(models.FloatField, graphene.Float)
|
||||
|
||||
|
||||
def test_should_float_convert_decimal():
|
||||
assert_conversion(models.DecimalField, graphene.Decimal)
|
||||
|
||||
|
||||
def test_should_manytomany_convert_connectionorlist():
|
||||
registry = Registry()
|
||||
dynamic_field = convert_django_field(Reporter._meta.local_many_to_many[0], registry)
|
||||
|
|
Loading…
Reference in New Issue
Block a user