Improved Django mapping

This commit is contained in:
Syrus Akbary 2015-09-29 18:25:56 -07:00
parent ee090b92bd
commit e89eb3456e
2 changed files with 22 additions and 8 deletions

View File

@ -19,31 +19,44 @@ def convert_django_field(field, cls):
@convert_django_field.register(models.DateField) @convert_django_field.register(models.DateField)
@convert_django_field.register(models.CharField) @convert_django_field.register(models.CharField)
@convert_django_field.register(models.TextField) @convert_django_field.register(models.TextField)
@convert_django_field.register(models.EmailField)
@convert_django_field.register(models.SlugField)
def _(field, cls): def _(field, cls):
return StringField(description=field.help_text) return StringField(description=field.description)
@convert_django_field.register(models.AutoField) @convert_django_field.register(models.AutoField)
def _(field, cls): 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.BigIntegerField)
@convert_django_field.register(models.URLField)
@convert_django_field.register(models.UUIDField)
@convert_django_field.register(models.IntegerField) @convert_django_field.register(models.IntegerField)
def _(field, cls): def _(field, cls):
return IntField(description=field.help_text) return IntField(description=field.description)
@convert_django_field.register(models.BooleanField) @convert_django_field.register(models.BooleanField)
def _(field, cls): 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) @convert_django_field.register(models.FloatField)
def _(field, cls): 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) @convert_django_field.register(models.ManyToOneRel)
def _(field, cls): def _(field, cls):
schema = cls._meta.schema schema = cls._meta.schema
@ -51,6 +64,7 @@ def _(field, cls):
return ConnectionOrListField(model_field) return ConnectionOrListField(model_field)
@convert_django_field.register(models.OneToOneField)
@convert_django_field.register(models.ForeignKey) @convert_django_field.register(models.ForeignKey)
def _(field, cls): def _(field, cls):
return DjangoModelField(field.related_model) return DjangoModelField(field.related_model, description=field.description)

View File

@ -31,8 +31,8 @@ class ConnectionOrListField(LazyField):
class DjangoModelField(Field): class DjangoModelField(Field):
def __init__(self, model): def __init__(self, model, *args, **kwargs):
super(DjangoModelField, self).__init__(None) super(DjangoModelField, self).__init__(None, *args, **kwargs)
self.model = model self.model = model
@cached_property @cached_property