Skip to content

Commit 8bb55ed

Browse files
committed
Get name of reverse_fields from model.__dict__
1 parent 94bab46 commit 8bb55ed

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

graphene_django/types.py

Lines changed: 1 addition & 2 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

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)