mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-10 19:57:15 +03:00
Merge pull request #368 from sciyoshi/convert-date-time
Convert Date/Time/DateTime form fields to appropriate Graphene types
This commit is contained in:
commit
94ee97085f
|
@ -2,6 +2,7 @@ from django import forms
|
|||
from django.forms.fields import BaseTemporalField
|
||||
|
||||
from graphene import ID, Boolean, Float, Int, List, String, UUID
|
||||
from graphene.types.datetime import Date, DateTime, Time
|
||||
|
||||
from .forms import GlobalIDFormField, GlobalIDMultipleChoiceField
|
||||
from .utils import import_single_dispatch
|
||||
|
@ -63,6 +64,21 @@ def convert_form_field_to_list(field):
|
|||
return List(ID, required=field.required)
|
||||
|
||||
|
||||
@convert_form_field.register(forms.DateField)
|
||||
def convert_form_field_to_date(field):
|
||||
return Date(description=field.help_text, required=field.required)
|
||||
|
||||
|
||||
@convert_form_field.register(forms.DateTimeField)
|
||||
def convert_form_field_to_datetime(field):
|
||||
return DateTime(description=field.help_text, required=field.required)
|
||||
|
||||
|
||||
@convert_form_field.register(forms.TimeField)
|
||||
def convert_form_field_to_time(field):
|
||||
return Time(description=field.help_text, required=field.required)
|
||||
|
||||
|
||||
@convert_form_field.register(forms.ModelChoiceField)
|
||||
@convert_form_field.register(GlobalIDFormField)
|
||||
def convert_form_field_to_id(field):
|
||||
|
|
|
@ -23,18 +23,18 @@ def test_should_unknown_django_field_raise_exception():
|
|||
assert 'Don\'t know how to convert the Django form field' in str(excinfo.value)
|
||||
|
||||
|
||||
def test_should_date_convert_string():
|
||||
assert_conversion(forms.DateField, graphene.String)
|
||||
def test_should_date_convert_date():
|
||||
assert_conversion(forms.DateField, graphene.types.datetime.Date)
|
||||
|
||||
|
||||
def test_should_time_convert_string():
|
||||
assert_conversion(forms.TimeField, graphene.String)
|
||||
def test_should_time_convert_time():
|
||||
assert_conversion(forms.TimeField, graphene.types.datetime.Time)
|
||||
|
||||
def test_should_date_convert_string():
|
||||
assert_conversion(forms.DateField, graphene.String)
|
||||
|
||||
def test_should_date_time_convert_string():
|
||||
assert_conversion(forms.DateTimeField, graphene.String)
|
||||
def test_should_date_time_convert_date_time():
|
||||
assert_conversion(forms.DateTimeField, graphene.types.datetime.DateTime)
|
||||
|
||||
|
||||
def test_should_char_convert_string():
|
||||
|
|
Loading…
Reference in New Issue
Block a user