-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Attempt to address Django 2.0 deprecate warnings related to field.rel #3906
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added a compatibility function to support versions prior to Django 1.9
- Loading branch information
commit 83e73cd5bb6d0518880d92677c7e0a44918d5a51
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,8 @@ | |
| from django.utils import six | ||
|
|
||
| from rest_framework.compat import ( | ||
| get_all_related_many_to_many_objects, get_all_related_objects | ||
| get_all_related_many_to_many_objects, get_all_related_objects, | ||
| get_remote_field | ||
| ) | ||
|
|
||
| FieldInfo = namedtuple('FieldResult', [ | ||
|
|
@@ -80,16 +81,16 @@ def get_field_info(model): | |
|
|
||
| def _get_pk(opts): | ||
| pk = opts.pk | ||
| while pk.remote_field and pk.remote_field.parent_link: | ||
| while get_remote_field(pk) and get_remote_field(pk).parent_link: | ||
| # If model is a child via multi-table inheritance, use parent's pk. | ||
| pk = pk.remote_field.to._meta.pk | ||
| pk = get_remote_field(pk).to._meta.pk | ||
|
|
||
| return pk | ||
|
|
||
|
|
||
| def _get_fields(opts): | ||
| fields = OrderedDict() | ||
| for field in [field for field in opts.fields if field.serialize and not field.remote_field]: | ||
| for field in [field for field in opts.fields if field.serialize and not get_remote_field(field)]: | ||
| fields[field.name] = field | ||
|
|
||
| return fields | ||
|
|
@@ -104,10 +105,10 @@ def _get_forward_relationships(opts): | |
| Returns an `OrderedDict` of field names to `RelationInfo`. | ||
| """ | ||
| forward_relations = OrderedDict() | ||
| for field in [field for field in opts.fields if field.serialize and field.remote_field]: | ||
| for field in [field for field in opts.fields if field.serialize and get_remote_field(field)]: | ||
| forward_relations[field.name] = RelationInfo( | ||
| model_field=field, | ||
| related_model=_resolve_model(field.remote_field.to), | ||
| related_model=_resolve_model(get_remote_field(field).to), | ||
| to_many=False, | ||
| to_field=_get_to_field(field), | ||
| has_through_model=False | ||
|
|
@@ -117,12 +118,12 @@ def _get_forward_relationships(opts): | |
| for field in [field for field in opts.many_to_many if field.serialize]: | ||
| forward_relations[field.name] = RelationInfo( | ||
| model_field=field, | ||
| related_model=_resolve_model(field.remote_field.to), | ||
| related_model=_resolve_model(get_remote_field(field).to), | ||
|
||
| to_many=True, | ||
| # manytomany do not have to_fields | ||
| to_field=None, | ||
| has_through_model=( | ||
| not field.remote_field.through._meta.auto_created | ||
| not get_remote_field(field).through._meta.auto_created | ||
| ) | ||
| ) | ||
|
|
||
|
|
@@ -144,7 +145,7 @@ def _get_reverse_relationships(opts): | |
| reverse_relations[accessor_name] = RelationInfo( | ||
| model_field=None, | ||
| related_model=related, | ||
| to_many=relation.field.remote_field.multiple, | ||
| to_many=get_remote_field(relation.field).multiple, | ||
| to_field=_get_to_field(relation.field), | ||
| has_through_model=False | ||
| ) | ||
|
|
@@ -160,8 +161,8 @@ def _get_reverse_relationships(opts): | |
| # manytomany do not have to_fields | ||
| to_field=None, | ||
| has_through_model=( | ||
| (getattr(relation.field.remote_field, 'through', None) is not None) and | ||
| not relation.field.remote_field.through._meta.auto_created | ||
| (getattr(get_remote_field(relation.field), 'through', None) is not None) and | ||
|
||
| not get_remote_field(relation.field).through._meta.auto_created | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we instead have this set in a var after line 83?
remote_field = get_remote_field(pk)and use throughout?