Skip to content

Commit eb02f87

Browse files
authored
Merge pull request graphql-python#74 from momamene/fix-reverse-fields-name
graphql-python#63 Get name of reverse_fields from model.__dict__
2 parents f6034ab + 45542b6 commit eb02f87

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

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)