Skip to content

Commit 401af42

Browse files
authored
Merge pull request #66 from pizzapanther/master
added timefield support
2 parents c60c143 + 0b76e1a commit 401af42

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

graphene_django/converter.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from graphene import (ID, Boolean, Dynamic, Enum, Field, Float, Int, List,
55
NonNull, String)
66
from graphene.relay import is_node
7-
from graphene.types.datetime import DateTime
7+
from graphene.types.datetime import DateTime, Time
88
from graphene.types.json import JSONString
99
from graphene.utils.str_converters import to_camel_case, to_const
1010
from graphql import assert_valid_name
@@ -112,6 +112,11 @@ def convert_date_to_string(field, registry=None):
112112
return DateTime(description=field.help_text, required=not field.null)
113113

114114

115+
@convert_django_field.register(models.TimeField)
116+
def convert_time_to_string(field, registry=None):
117+
return Time(description=field.help_text, required=not field.null)
118+
119+
115120
@convert_django_field.register(models.OneToOneRel)
116121
def convert_onetoone_field_to_djangomodel(field, registry=None):
117122
model = get_related_model(field)

graphene_django/tests/test_converter.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import graphene
77
from graphene.relay import ConnectionField, Node
8-
from graphene.types.datetime import DateTime
8+
from graphene.types.datetime import DateTime, Time
99
from graphene.types.json import JSONString
1010

1111
from ..compat import (ArrayField, HStoreField, JSONField, MissingType,
@@ -16,7 +16,7 @@
1616
from .models import Article, Film, FilmDetails, Reporter
1717

1818

19-
# from graphene.core.types.custom_scalars import DateTime, JSONString
19+
# from graphene.core.types.custom_scalars import DateTime, Time, JSONString
2020

2121

2222
def assert_conversion(django_field, graphene_field, *args, **kwargs):
@@ -44,6 +44,10 @@ def test_should_date_convert_string():
4444
assert_conversion(models.DateField, DateTime)
4545

4646

47+
def test_should_time_convert_string():
48+
assert_conversion(models.TimeField, Time)
49+
50+
4751
def test_should_char_convert_string():
4852
assert_conversion(models.CharField, graphene.String)
4953

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
install_requires=[
3535
'six>=1.10.0',
36-
'graphene>=1.0',
36+
'graphene>=1.1.2',
3737
'Django>=1.6.0',
3838
'iso8601',
3939
'singledispatch>=3.4.0.3',

0 commit comments

Comments
 (0)