Merge pull request #74 from momamene/fix-reverse-fields-name

#63 Get name of reverse_fields from model.__dict__
This commit is contained in:
Syrus Akbary 2017-03-15 21:37:48 -07:00 committed by GitHub
commit eb02f8781c
2 changed files with 11 additions and 9 deletions

View File

@ -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
@ -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

View File

@ -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):
@ -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