Improved field description converter from Django fields

This commit is contained in:
Syrus Akbary 2015-10-06 00:49:13 -07:00
parent fe510dc686
commit 0843499306
3 changed files with 10 additions and 8 deletions

View File

@ -26,12 +26,12 @@ def convert_django_field(field):
@convert_django_field.register(models.URLField) @convert_django_field.register(models.URLField)
@convert_django_field.register(models.UUIDField) @convert_django_field.register(models.UUIDField)
def _(field): def _(field):
return StringField(description=field.description) return StringField(description=field.help_text)
@convert_django_field.register(models.AutoField) @convert_django_field.register(models.AutoField)
def _(field): def _(field):
return IDField(description=field.description) return IDField(description=field.help_text)
@convert_django_field.register(models.PositiveIntegerField) @convert_django_field.register(models.PositiveIntegerField)
@ -40,22 +40,22 @@ def _(field):
@convert_django_field.register(models.BigIntegerField) @convert_django_field.register(models.BigIntegerField)
@convert_django_field.register(models.IntegerField) @convert_django_field.register(models.IntegerField)
def _(field): def _(field):
return IntField(description=field.description) return IntField(description=field.help_text)
@convert_django_field.register(models.BooleanField) @convert_django_field.register(models.BooleanField)
def _(field): def _(field):
return BooleanField(description=field.description, required=True) return BooleanField(description=field.help_text, required=True)
@convert_django_field.register(models.NullBooleanField) @convert_django_field.register(models.NullBooleanField)
def _(field): def _(field):
return BooleanField(description=field.description) return BooleanField(description=field.help_text)
@convert_django_field.register(models.FloatField) @convert_django_field.register(models.FloatField)
def _(field): def _(field):
return FloatField(description=field.description) return FloatField(description=field.help_text)
@convert_django_field.register(models.ManyToManyField) @convert_django_field.register(models.ManyToManyField)
@ -68,4 +68,4 @@ def _(field):
@convert_django_field.register(models.OneToOneField) @convert_django_field.register(models.OneToOneField)
@convert_django_field.register(models.ForeignKey) @convert_django_field.register(models.ForeignKey)
def _(field): def _(field):
return DjangoModelField(field.related_model, description=field.description) return DjangoModelField(field.related_model, description=field.help_text)

View File

@ -100,6 +100,7 @@ class Field(object):
internal_type = self.internal_type(schema) internal_type = self.internal_type(schema)
if not internal_type: if not internal_type:
raise Exception("Internal type for field %s is None" % self) raise Exception("Internal type for field %s is None" % self)
return GraphQLField( return GraphQLField(
internal_type, internal_type,
description=self.description, description=self.description,

View File

@ -15,9 +15,10 @@ from .models import Article, Reporter
def assert_conversion(django_field, graphene_field, *args): def assert_conversion(django_field, graphene_field, *args):
field = django_field(*args) field = django_field(*args, help_text='Custom Help Text')
graphene_type = convert_django_field(field) graphene_type = convert_django_field(field)
assert isinstance(graphene_type, graphene_field) assert isinstance(graphene_type, graphene_field)
assert graphene_type.description == 'Custom Help Text'
return graphene_type return graphene_type