fix choices enum: if field can be blank then it isnt required (#714)

This commit is contained in:
Jason Kraus 2019-08-01 01:07:52 -07:00 committed by Jonathan Kim
parent 51adb3632b
commit b1a9293016
3 changed files with 4 additions and 3 deletions

View File

@ -73,7 +73,8 @@ def convert_django_field_with_choices(
return named_choices_descriptions[self.name]
enum = Enum(name, list(named_choices), type=EnumWithDescriptionsType)
converted = enum(description=field.help_text, required=not field.null)
required = not (field.blank or field.null)
converted = enum(description=field.help_text, required=required)
else:
converted = convert_django_field(field, registry)
if registry is not None:

View File

@ -38,7 +38,7 @@ class Reporter(models.Model):
last_name = models.CharField(max_length=30)
email = models.EmailField()
pets = models.ManyToManyField("self")
a_choice = models.CharField(max_length=30, choices=CHOICES)
a_choice = models.CharField(max_length=30, choices=CHOICES, blank=True)
objects = models.Manager()
doe_objects = DoeReporterManager()

View File

@ -171,7 +171,7 @@ type Reporter {
lastName: String!
email: String!
pets: [Reporter!]!
aChoice: ReporterAChoice!
aChoice: ReporterAChoice
reporterType: ReporterReporterType
articles(before: String, after: String, first: Int, last: Int): ArticleConnection
}