mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 17:46:57 +03:00
Improved Django mapping
This commit is contained in:
parent
ee090b92bd
commit
e89eb3456e
|
@ -19,31 +19,44 @@ def convert_django_field(field, cls):
|
|||
@convert_django_field.register(models.DateField)
|
||||
@convert_django_field.register(models.CharField)
|
||||
@convert_django_field.register(models.TextField)
|
||||
@convert_django_field.register(models.EmailField)
|
||||
@convert_django_field.register(models.SlugField)
|
||||
def _(field, cls):
|
||||
return StringField(description=field.help_text)
|
||||
return StringField(description=field.description)
|
||||
|
||||
|
||||
@convert_django_field.register(models.AutoField)
|
||||
def _(field, cls):
|
||||
return IDField(description=field.help_text)
|
||||
return IDField(description=field.description)
|
||||
|
||||
|
||||
@convert_django_field.register(models.PositiveIntegerField)
|
||||
@convert_django_field.register(models.PositiveSmallIntegerField)
|
||||
@convert_django_field.register(models.SmallIntegerField)
|
||||
@convert_django_field.register(models.BigIntegerField)
|
||||
@convert_django_field.register(models.URLField)
|
||||
@convert_django_field.register(models.UUIDField)
|
||||
@convert_django_field.register(models.IntegerField)
|
||||
def _(field, cls):
|
||||
return IntField(description=field.help_text)
|
||||
return IntField(description=field.description)
|
||||
|
||||
|
||||
@convert_django_field.register(models.BooleanField)
|
||||
def _(field, cls):
|
||||
return BooleanField(description=field.help_text)
|
||||
return BooleanField(description=field.description, null=False)
|
||||
|
||||
|
||||
@convert_django_field.register(models.NullBooleanField)
|
||||
def _(field, cls):
|
||||
return BooleanField(description=field.description)
|
||||
|
||||
|
||||
@convert_django_field.register(models.FloatField)
|
||||
def _(field, cls):
|
||||
return FloatField(description=field.help_text)
|
||||
return FloatField(description=field.description)
|
||||
|
||||
|
||||
@convert_django_field.register(models.ManyToManyField)
|
||||
@convert_django_field.register(models.ManyToOneRel)
|
||||
def _(field, cls):
|
||||
schema = cls._meta.schema
|
||||
|
@ -51,6 +64,7 @@ def _(field, cls):
|
|||
return ConnectionOrListField(model_field)
|
||||
|
||||
|
||||
@convert_django_field.register(models.OneToOneField)
|
||||
@convert_django_field.register(models.ForeignKey)
|
||||
def _(field, cls):
|
||||
return DjangoModelField(field.related_model)
|
||||
return DjangoModelField(field.related_model, description=field.description)
|
||||
|
|
|
@ -31,8 +31,8 @@ class ConnectionOrListField(LazyField):
|
|||
|
||||
|
||||
class DjangoModelField(Field):
|
||||
def __init__(self, model):
|
||||
super(DjangoModelField, self).__init__(None)
|
||||
def __init__(self, model, *args, **kwargs):
|
||||
super(DjangoModelField, self).__init__(None, *args, **kwargs)
|
||||
self.model = model
|
||||
|
||||
@cached_property
|
||||
|
|
Loading…
Reference in New Issue
Block a user