Charfield blank=True fix v2

This commit is contained in:
Zoltan Egyed 2018-09-26 13:42:36 +02:00
parent 6ed8269175
commit dd1e1691cd
3 changed files with 10 additions and 1 deletions

View File

@ -61,6 +61,14 @@ def convert_django_field_with_choices(field, registry=None):
if choices:
meta = field.model._meta
name = to_camel_case("{}_{}".format(meta.object_name, field.name))
# Not null fields with choices and blank=True and without default value
if (
field.blank and
not field.null and
field.default == models.fields.NOT_PROVIDED
):
choices = list(choices)
choices.append(('', ''))
choices = list(get_choices(choices))
named_choices = [(c[0], c[1]) for c in choices]
named_choices_descriptions = {c[0]: c[2] for c in choices}

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

@ -174,6 +174,7 @@ type Reporter {
enum ReporterAChoice {
A_1
A_2
A_
}
enum ReporterReporterType {