mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-14 02:02:20 +03:00
Merge dd1e1691cd
into f76f38ef30
This commit is contained in:
commit
f2c4b554bb
|
@ -61,6 +61,14 @@ def convert_django_field_with_choices(field, registry=None):
|
||||||
if choices:
|
if choices:
|
||||||
meta = field.model._meta
|
meta = field.model._meta
|
||||||
name = to_camel_case("{}_{}".format(meta.object_name, field.name))
|
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))
|
choices = list(get_choices(choices))
|
||||||
named_choices = [(c[0], c[1]) for c in choices]
|
named_choices = [(c[0], c[1]) for c in choices]
|
||||||
named_choices_descriptions = {c[0]: c[2] for c in choices}
|
named_choices_descriptions = {c[0]: c[2] for c in choices}
|
||||||
|
@ -71,7 +79,8 @@ def convert_django_field_with_choices(field, registry=None):
|
||||||
return named_choices_descriptions[self.name]
|
return named_choices_descriptions[self.name]
|
||||||
|
|
||||||
enum = Enum(name, list(named_choices), type=EnumWithDescriptionsType)
|
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 or field.default)
|
||||||
|
converted = enum(description=field.help_text, required=required)
|
||||||
else:
|
else:
|
||||||
converted = convert_django_field(field, registry)
|
converted = convert_django_field(field, registry)
|
||||||
if registry is not None:
|
if registry is not None:
|
||||||
|
|
|
@ -38,7 +38,7 @@ class Reporter(models.Model):
|
||||||
last_name = models.CharField(max_length=30)
|
last_name = models.CharField(max_length=30)
|
||||||
email = models.EmailField()
|
email = models.EmailField()
|
||||||
pets = models.ManyToManyField("self")
|
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()
|
objects = models.Manager()
|
||||||
doe_objects = DoeReporterManager()
|
doe_objects = DoeReporterManager()
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ type Article implements Node {
|
||||||
pubDateTime: DateTime!
|
pubDateTime: DateTime!
|
||||||
reporter: Reporter!
|
reporter: Reporter!
|
||||||
editor: Reporter!
|
editor: Reporter!
|
||||||
lang: ArticleLang!
|
lang: ArticleLang
|
||||||
importance: ArticleImportance
|
importance: ArticleImportance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ type Reporter {
|
||||||
lastName: String!
|
lastName: String!
|
||||||
email: String!
|
email: String!
|
||||||
pets: [Reporter]
|
pets: [Reporter]
|
||||||
aChoice: ReporterAChoice!
|
aChoice: ReporterAChoice
|
||||||
reporterType: ReporterReporterType
|
reporterType: ReporterReporterType
|
||||||
articles(before: String, after: String, first: Int, last: Int): ArticleConnection
|
articles(before: String, after: String, first: Int, last: Int): ArticleConnection
|
||||||
}
|
}
|
||||||
|
@ -174,6 +174,7 @@ type Reporter {
|
||||||
enum ReporterAChoice {
|
enum ReporterAChoice {
|
||||||
A_1
|
A_1
|
||||||
A_2
|
A_2
|
||||||
|
A_
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ReporterReporterType {
|
enum ReporterReporterType {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user