Update converter.py

This commit is contained in:
Momotv45 2016-10-07 17:21:15 +01:00 committed by GitHub
parent 6b75358008
commit ab5e118975

View File

@ -49,31 +49,34 @@ def convert_django_field_with_choices(field, registry=None):
enum = Enum(name, list(named_choices), type=EnumWithDescriptionsType) enum = Enum(name, list(named_choices), type=EnumWithDescriptionsType)
return enum(description=field.help_text, required=not field.null) return enum(description=field.help_text, required=not field.null)
return convert_django_field(field, registry) return convert_django_field(field, registry)
@singledispatch @singledispatch
def convert_django_field(field, registry=None): def convert_django_field(field, registry=None):
raise Exception( raise Exception(
"Don't know how to convert the Django field %s (%s)" % "Don't know how to convert the Django field %s (%s)" %
(field, field.__class__)) (field, field.__class__))
def get_phone_number_field(): def get_phone_number_field():
try: try:
from phonenumber_field.formfields import PhoneNumberField from phonenumber_field.formfields import PhoneNumberField
return PhoneNumberField return PhoneNumberField
except: except:
try: try:
return models.DurationField return models.DurationField
except: except:
pass pass
return models.CharField return models.CharField
def get_duration_field(): def get_duration_field():
try: try:
return models.DurationField return models.DurationField
except: except:
return models.CharField return models.CharField
@convert_django_field.register(get_phone_number_field()) @convert_django_field.register(get_phone_number_field())
@convert_django_field.register(get_duration_field()) @convert_django_field.register(get_duration_field())
@convert_django_field.register(models.CharField) @convert_django_field.register(models.CharField)