Skip to content

[WIP] fix remote_field deprecation warning #4062

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
wants to merge 2 commits into from
Closed
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
15 changes: 15 additions & 0 deletions rest_framework/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,18 @@ def template_render(template, context=None, request=None):
# backends template, e.g. django.template.backends.django.Template
else:
return template.render(context, request=request)

def get_remote_field(field):
"""
Django 1.9 removed usage of Rel objects, see
https://github.com/django/django/pull/4241

:param field: Field
:return: remote field
"""
from django.db.models import fields

if django.VERSION < (1, 9):
return field.rel
else:
return field.remote_field
6 changes: 4 additions & 2 deletions rest_framework/utils/model_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from django.core.exceptions import ImproperlyConfigured
from django.db import models
from django.utils import six
from rest_framework.compat import get_remote_field

FieldInfo = namedtuple('FieldResult', [
'pk', # Model field instance
Expand Down Expand Up @@ -76,9 +77,10 @@ def get_field_info(model):

def _get_pk(opts):
pk = opts.pk
while pk.rel and pk.rel.parent_link:
remote_field = get_remote_field(pk)
while remote_field and remote_field.parent_link:
# If model is a child via multi-table inheritance, use parent's pk.
pk = pk.rel.to._meta.pk
pk = remote_field.to._meta.pk

return pk

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy