mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-11 08:42:32 +03:00
Convert form DecimalField to Decimal
This commit is contained in:
parent
0b8bc61153
commit
d9e4055a65
|
@ -5,7 +5,7 @@ import pytest
|
||||||
from django.db.models import TextField, Value
|
from django.db.models import TextField, Value
|
||||||
from django.db.models.functions import Concat
|
from django.db.models.functions import Concat
|
||||||
|
|
||||||
from graphene import Argument, Boolean, Field, Float, ObjectType, Schema, String
|
from graphene import Argument, Boolean, Decimal, Field, ObjectType, Schema, String
|
||||||
from graphene.relay import Node
|
from graphene.relay import Node
|
||||||
from graphene_django import DjangoObjectType
|
from graphene_django import DjangoObjectType
|
||||||
from graphene_django.forms import GlobalIDFormField, GlobalIDMultipleChoiceField
|
from graphene_django.forms import GlobalIDFormField, GlobalIDMultipleChoiceField
|
||||||
|
@ -401,7 +401,7 @@ def test_filterset_descriptions():
|
||||||
field = DjangoFilterConnectionField(ArticleNode, filterset_class=ArticleIdFilter)
|
field = DjangoFilterConnectionField(ArticleNode, filterset_class=ArticleIdFilter)
|
||||||
max_time = field.args["max_time"]
|
max_time = field.args["max_time"]
|
||||||
assert isinstance(max_time, Argument)
|
assert isinstance(max_time, Argument)
|
||||||
assert max_time.type == Float
|
assert max_time.type == Decimal
|
||||||
assert max_time.description == "The maximum time"
|
assert max_time.description == "The maximum time"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,19 @@ from functools import singledispatch
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
|
|
||||||
from graphene import ID, Boolean, Float, Int, List, String, UUID, Date, DateTime, Time
|
from graphene import (
|
||||||
|
ID,
|
||||||
|
Boolean,
|
||||||
|
Decimal,
|
||||||
|
Float,
|
||||||
|
Int,
|
||||||
|
List,
|
||||||
|
String,
|
||||||
|
UUID,
|
||||||
|
Date,
|
||||||
|
DateTime,
|
||||||
|
Time,
|
||||||
|
)
|
||||||
|
|
||||||
from .forms import GlobalIDFormField, GlobalIDMultipleChoiceField
|
from .forms import GlobalIDFormField, GlobalIDMultipleChoiceField
|
||||||
|
|
||||||
|
@ -57,12 +69,18 @@ def convert_form_field_to_nullboolean(field):
|
||||||
return Boolean(description=get_form_field_description(field))
|
return Boolean(description=get_form_field_description(field))
|
||||||
|
|
||||||
|
|
||||||
@convert_form_field.register(forms.DecimalField)
|
|
||||||
@convert_form_field.register(forms.FloatField)
|
@convert_form_field.register(forms.FloatField)
|
||||||
def convert_form_field_to_float(field):
|
def convert_form_field_to_float(field):
|
||||||
return Float(description=get_form_field_description(field), required=field.required)
|
return Float(description=get_form_field_description(field), required=field.required)
|
||||||
|
|
||||||
|
|
||||||
|
@convert_form_field.register(forms.DecimalField)
|
||||||
|
def convert_form_field_to_decimal(field):
|
||||||
|
return Decimal(
|
||||||
|
description=get_form_field_description(field), required=field.required
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@convert_form_field.register(forms.MultipleChoiceField)
|
@convert_form_field.register(forms.MultipleChoiceField)
|
||||||
def convert_form_field_to_string_list(field):
|
def convert_form_field_to_string_list(field):
|
||||||
return List(
|
return List(
|
||||||
|
|
|
@ -6,6 +6,7 @@ from graphene import (
|
||||||
String,
|
String,
|
||||||
Int,
|
Int,
|
||||||
Boolean,
|
Boolean,
|
||||||
|
Decimal,
|
||||||
Float,
|
Float,
|
||||||
ID,
|
ID,
|
||||||
UUID,
|
UUID,
|
||||||
|
@ -97,8 +98,8 @@ def test_should_float_convert_float():
|
||||||
assert_conversion(forms.FloatField, Float)
|
assert_conversion(forms.FloatField, Float)
|
||||||
|
|
||||||
|
|
||||||
def test_should_decimal_convert_float():
|
def test_should_decimal_convert_decimal():
|
||||||
assert_conversion(forms.DecimalField, Float)
|
assert_conversion(forms.DecimalField, Decimal)
|
||||||
|
|
||||||
|
|
||||||
def test_should_multiple_choice_convert_list():
|
def test_should_multiple_choice_convert_list():
|
||||||
|
|
Loading…
Reference in New Issue
Block a user