Skip to content

Commit 055c6e2

Browse files
committed
Merge branch 'master' into fix-filter-and-resolver
2 parents 2117cb2 + 005bb7f commit 055c6e2

File tree

7 files changed

+54
-15
lines changed

7 files changed

+54
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ py.test graphene_django --cov=graphene_django # Use -v -s for verbose mode
111111

112112
### Documentation
113113

114-
The documentation is generated using the excellent [Sphinx](http://www.sphinx-doc.org/) and a custom theme.
114+
The [documentation](http://docs.graphene-python.org/projects/django/en/latest/) is generated using the excellent [Sphinx](http://www.sphinx-doc.org/) and a custom theme.
115115

116116
The documentation dependencies are installed by running:
117117

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ After developing, the full test suite can be evaluated by running:
120120
Documentation
121121
~~~~~~~~~~~~~
122122

123-
The documentation is generated using the excellent
123+
The `documentation <http://docs.graphene-python.org/projects/django/en/latest/>`__ is generated using the excellent
124124
`Sphinx <http://www.sphinx-doc.org/>`__ and a custom theme.
125125

126126
The documentation dependencies are installed by running:
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
graphene
22
graphene-django
3-
django_graphiql
43
graphql-core
54
django==1.9

examples/cookbook/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
graphene
22
graphene-django
3-
django_graphiql
43
graphql-core
54
django==1.9
65
django-filter==0.11.0

graphene_django/tests/test_types.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
from graphene import Interface, ObjectType, Schema
44
from graphene.relay import Node
55

6-
from ..registry import reset_global_registry
6+
from .. import registry
77
from ..types import DjangoObjectType
88
from .models import Article as ArticleModel
99
from .models import Reporter as ReporterModel
1010

11-
reset_global_registry()
11+
registry.reset_global_registry()
1212

1313

1414
class Reporter(DjangoObjectType):
@@ -124,3 +124,42 @@ def test_schema_representation():
124124
}
125125
""".lstrip()
126126
assert str(schema) == expected
127+
128+
129+
def with_local_registry(func):
130+
def inner(*args, **kwargs):
131+
old = registry.get_global_registry()
132+
registry.reset_global_registry()
133+
try:
134+
retval = func(*args, **kwargs)
135+
except Exception as e:
136+
registry.registry = old
137+
raise e
138+
else:
139+
registry.registry = old
140+
return retval
141+
return inner
142+
143+
144+
@with_local_registry
145+
def test_django_objecttype_only_fields():
146+
class Reporter(DjangoObjectType):
147+
class Meta:
148+
model = ReporterModel
149+
only_fields = ('id', 'email', 'films')
150+
151+
152+
fields = list(Reporter._meta.fields.keys())
153+
assert fields == ['id', 'email', 'films']
154+
155+
156+
@with_local_registry
157+
def test_django_objecttype_exclude_fields():
158+
class Reporter(DjangoObjectType):
159+
class Meta:
160+
model = ReporterModel
161+
exclude_fields = ('email')
162+
163+
164+
fields = list(Reporter._meta.fields.keys())
165+
assert 'email' not in fields

graphene_django/types.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ def construct_fields(options):
2121
exclude_fields = options.exclude_fields
2222

2323
fields = OrderedDict()
24-
for field in _model_fields:
25-
name = field.name
24+
for name, field in _model_fields:
2625
is_not_in_only = only_fields and name not in options.only_fields
2726
is_already_created = name in options.fields
2827
is_excluded = name in exclude_fields or is_already_created
@@ -34,8 +33,6 @@ def construct_fields(options):
3433
# Or when there is no back reference.
3534
continue
3635
converted = convert_django_field_with_choices(field, options.registry)
37-
if not converted:
38-
continue
3936
fields[name] = converted
4037

4138
return fields

graphene_django/utils.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ def get_reverse_fields(model):
3030
# Hack for making it compatible with Django 1.6
3131
new_related = RelatedObject(related.parent_model, related.model, related.field)
3232
new_related.name = name
33-
yield new_related
33+
yield (name, new_related)
3434
elif isinstance(related, models.ManyToOneRel):
35-
yield related
35+
yield (name, related)
3636
elif isinstance(related, models.ManyToManyRel) and not related.symmetrical:
37-
yield related
37+
yield (name, related)
3838

3939

4040
def maybe_queryset(value):
@@ -45,8 +45,13 @@ def maybe_queryset(value):
4545

4646
def get_model_fields(model):
4747
reverse_fields = get_reverse_fields(model)
48-
all_fields = sorted(list(model._meta.fields) +
49-
list(model._meta.local_many_to_many))
48+
all_fields = [
49+
(field.name, field)
50+
for field
51+
in sorted(list(model._meta.fields) +
52+
list(model._meta.local_many_to_many))
53+
]
54+
5055
all_fields += list(reverse_fields)
5156

5257
return all_fields

0 commit comments

Comments
 (0)