Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
4f276974
Commit
4f276974
authored
Aug 27, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix get_model import
parent
f691006f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
4 deletions
+12
-4
rest_framework/compat.py
+8
-0
rest_framework/utils/model_meta.py
+2
-2
tests/test_utils.py
+2
-2
No files found.
rest_framework/compat.py
View file @
4f276974
...
@@ -82,6 +82,14 @@ except ImportError:
...
@@ -82,6 +82,14 @@ except ImportError:
postgres_fields
=
None
postgres_fields
=
None
# Apps only exists from 1.7 onwards.
try
:
from
django.apps
import
apps
get_model
=
apps
.
get_model
except
ImportError
:
from
django.db.models
import
get_model
# django-filter is optional
# django-filter is optional
try
:
try
:
import
django_filters
import
django_filters
...
...
rest_framework/utils/model_meta.py
View file @
4f276974
...
@@ -12,7 +12,7 @@ from django.core.exceptions import ImproperlyConfigured
...
@@ -12,7 +12,7 @@ from django.core.exceptions import ImproperlyConfigured
from
django.db
import
models
from
django.db
import
models
from
django.utils
import
six
from
django.utils
import
six
from
rest_framework.compat
import
OrderedDict
from
rest_framework.compat
import
OrderedDict
,
get_model
FieldInfo
=
namedtuple
(
'FieldResult'
,
[
FieldInfo
=
namedtuple
(
'FieldResult'
,
[
'pk'
,
# Model field instance
'pk'
,
# Model field instance
...
@@ -45,7 +45,7 @@ def _resolve_model(obj):
...
@@ -45,7 +45,7 @@ def _resolve_model(obj):
"""
"""
if
isinstance
(
obj
,
six
.
string_types
)
and
len
(
obj
.
split
(
'.'
))
==
2
:
if
isinstance
(
obj
,
six
.
string_types
)
and
len
(
obj
.
split
(
'.'
))
==
2
:
app_name
,
model_name
=
obj
.
split
(
'.'
)
app_name
,
model_name
=
obj
.
split
(
'.'
)
resolved_model
=
models
.
get_model
(
app_name
,
model_name
)
resolved_model
=
get_model
(
app_name
,
model_name
)
if
resolved_model
is
None
:
if
resolved_model
is
None
:
msg
=
"Django did not return a model for {0}.{1}"
msg
=
"Django did not return a model for {0}.{1}"
raise
ImproperlyConfigured
(
msg
.
format
(
app_name
,
model_name
))
raise
ImproperlyConfigured
(
msg
.
format
(
app_name
,
model_name
))
...
...
tests/test_utils.py
View file @
4f276974
...
@@ -150,12 +150,12 @@ class ResolveModelWithPatchedDjangoTests(TestCase):
...
@@ -150,12 +150,12 @@ class ResolveModelWithPatchedDjangoTests(TestCase):
def
setUp
(
self
):
def
setUp
(
self
):
"""Monkeypatch get_model."""
"""Monkeypatch get_model."""
self
.
get_model
=
rest_framework
.
utils
.
model_meta
.
models
.
get_model
self
.
get_model
=
rest_framework
.
utils
.
model_meta
.
get_model
def
get_model
(
app_label
,
model_name
):
def
get_model
(
app_label
,
model_name
):
return
None
return
None
rest_framework
.
utils
.
model_meta
.
models
.
get_model
=
get_model
rest_framework
.
utils
.
model_meta
.
get_model
=
get_model
def
tearDown
(
self
):
def
tearDown
(
self
):
"""Revert monkeypatching."""
"""Revert monkeypatching."""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment