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
6e86a53c
Commit
6e86a53c
authored
Sep 22, 2015
by
Carlton Gibson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove `apps.get_model` fallback
* Corrects presumed logic error in `ResolveModelWithPatchedDjangoTests`
parent
68c88e18
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
13 deletions
+6
-13
rest_framework/compat.py
+0
-8
rest_framework/utils/model_meta.py
+3
-2
tests/test_utils.py
+3
-3
No files found.
rest_framework/compat.py
View file @
6e86a53c
...
...
@@ -82,14 +82,6 @@ except ImportError:
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
try
:
import
django_filters
...
...
rest_framework/utils/model_meta.py
View file @
6e86a53c
...
...
@@ -8,11 +8,12 @@ Usage: `get_field_info(model)` returns a `FieldInfo` instance.
import
inspect
from
collections
import
namedtuple
from
django.apps
import
apps
from
django.core.exceptions
import
ImproperlyConfigured
from
django.db
import
models
from
django.utils
import
six
from
rest_framework.compat
import
OrderedDict
,
get_model
from
rest_framework.compat
import
OrderedDict
FieldInfo
=
namedtuple
(
'FieldResult'
,
[
'pk'
,
# Model field instance
...
...
@@ -45,7 +46,7 @@ def _resolve_model(obj):
"""
if
isinstance
(
obj
,
six
.
string_types
)
and
len
(
obj
.
split
(
'.'
))
==
2
:
app_name
,
model_name
=
obj
.
split
(
'.'
)
resolved_model
=
get_model
(
app_name
,
model_name
)
resolved_model
=
apps
.
get_model
(
app_name
,
model_name
)
if
resolved_model
is
None
:
msg
=
"Django did not return a model for {0}.{1}"
raise
ImproperlyConfigured
(
msg
.
format
(
app_name
,
model_name
))
...
...
tests/test_utils.py
View file @
6e86a53c
...
...
@@ -150,16 +150,16 @@ class ResolveModelWithPatchedDjangoTests(TestCase):
def
setUp
(
self
):
"""Monkeypatch get_model."""
self
.
get_model
=
rest_framework
.
utils
.
model_meta
.
get_model
self
.
get_model
=
rest_framework
.
utils
.
model_meta
.
apps
.
get_model
def
get_model
(
app_label
,
model_name
):
return
None
rest_framework
.
utils
.
model_meta
.
get_model
=
get_model
rest_framework
.
utils
.
model_meta
.
apps
.
get_model
=
get_model
def
tearDown
(
self
):
"""Revert monkeypatching."""
rest_framework
.
utils
.
model_meta
.
model
s
.
get_model
=
self
.
get_model
rest_framework
.
utils
.
model_meta
.
app
s
.
get_model
=
self
.
get_model
def
test_blows_up_if_model_does_not_resolve
(
self
):
with
self
.
assertRaises
(
ImproperlyConfigured
):
...
...
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