Skip to content

#63 Get name of reverse_fields from model.__dict__ #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions graphene_django/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def construct_fields(options):
exclude_fields = options.exclude_fields

fields = OrderedDict()
for field in _model_fields:
name = field.name
for name, field in _model_fields:
is_not_in_only = only_fields and name not in options.only_fields
is_already_created = name in options.fields
is_excluded = name in exclude_fields or is_already_created
Expand All @@ -34,8 +33,6 @@ def construct_fields(options):
# Or when there is no back reference.
continue
converted = convert_django_field_with_choices(field, options.registry)
if not converted:
continue
fields[name] = converted

return fields
Expand Down
15 changes: 10 additions & 5 deletions graphene_django/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def get_reverse_fields(model):
# Hack for making it compatible with Django 1.6
new_related = RelatedObject(related.parent_model, related.model, related.field)
new_related.name = name
yield new_related
yield (name, new_related)
elif isinstance(related, models.ManyToOneRel):
yield related
yield (name, related)
elif isinstance(related, models.ManyToManyRel) and not related.symmetrical:
yield related
yield (name, related)


def maybe_queryset(value):
Expand All @@ -45,8 +45,13 @@ def maybe_queryset(value):

def get_model_fields(model):
reverse_fields = get_reverse_fields(model)
all_fields = sorted(list(model._meta.fields) +
list(model._meta.local_many_to_many))
all_fields = [
(field.name, field)
for field
in sorted(list(model._meta.fields) +
list(model._meta.local_many_to_many))
]

all_fields += list(reverse_fields)

return all_fields
Expand Down