mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-13 17:52:19 +03:00
support blank fields with choices
This commit is contained in:
parent
ea2cd9894f
commit
98de592303
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -78,3 +78,7 @@ Session.vim
|
|||
*~
|
||||
# auto-generated tag files
|
||||
tags
|
||||
|
||||
# Pipenv
|
||||
Pipfile
|
||||
Pipfile.lock
|
||||
|
|
|
@ -62,6 +62,8 @@ def convert_django_field_with_choices(field, registry=None):
|
|||
meta = field.model._meta
|
||||
name = to_camel_case("{}_{}".format(meta.object_name, field.name))
|
||||
choices = list(get_choices(choices))
|
||||
if field.blank:
|
||||
choices.append(('EMPTY', '', ''))
|
||||
named_choices = [(c[0], c[1]) for c in choices]
|
||||
named_choices_descriptions = {c[0]: c[2] for c in choices}
|
||||
|
||||
|
|
|
@ -196,6 +196,22 @@ def test_field_with_choices_collision():
|
|||
convert_django_field_with_choices(field)
|
||||
|
||||
|
||||
def test_field_with_blank():
|
||||
field = models.CharField(
|
||||
help_text="Language", choices=(("es", "Spanish"), ("en", "English")), blank=True
|
||||
)
|
||||
|
||||
class TranslatedModel(models.Model):
|
||||
language = field
|
||||
|
||||
class Meta:
|
||||
app_label = "test"
|
||||
|
||||
graphene_type = convert_django_field_with_choices(field)
|
||||
assert graphene_type._meta.enum.__members__["EMPTY"].value == ""
|
||||
assert graphene_type._meta.enum.__members__["EMPTY"].description == ""
|
||||
|
||||
|
||||
def test_should_float_convert_float():
|
||||
assert_conversion(models.FloatField, graphene.Float)
|
||||
|
||||
|
@ -241,7 +257,7 @@ def test_should_manytoone_convert_connectionorlist():
|
|||
class Meta:
|
||||
model = Article
|
||||
|
||||
graphene_field = convert_django_field(Reporter.articles.rel,
|
||||
graphene_field = convert_django_field(Reporter.articles.rel,
|
||||
A._meta.registry)
|
||||
assert isinstance(graphene_field, graphene.Dynamic)
|
||||
dynamic_field = graphene_field.get_type()
|
||||
|
|
|
@ -138,6 +138,7 @@ type ArticleEdge {
|
|||
enum ArticleImportance {
|
||||
A_1
|
||||
A_2
|
||||
EMPTY
|
||||
}
|
||||
|
||||
enum ArticleLang {
|
||||
|
@ -179,6 +180,7 @@ enum ReporterAChoice {
|
|||
enum ReporterReporterType {
|
||||
A_1
|
||||
A_2
|
||||
EMPTY
|
||||
}
|
||||
|
||||
type RootQuery {
|
||||
|
|
Loading…
Reference in New Issue
Block a user