aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rest_framework/utils/model_meta.py7
-rw-r--r--tests/test_utils.py3
2 files changed, 6 insertions, 4 deletions
diff --git a/rest_framework/utils/model_meta.py b/rest_framework/utils/model_meta.py
index 54f9310d..c98725c6 100644
--- a/rest_framework/utils/model_meta.py
+++ b/rest_framework/utils/model_meta.py
@@ -6,6 +6,7 @@ relationships and their associated metadata.
Usage: `get_field_info(model)` returns a `FieldInfo` instance.
"""
from collections import namedtuple
+from django.core.exceptions import ImproperlyConfigured
from django.db import models
from django.utils import six
from rest_framework.compat import OrderedDict
@@ -44,9 +45,9 @@ def _resolve_model(obj):
if isinstance(obj, six.string_types) and len(obj.split('.')) == 2:
app_name, model_name = obj.split('.')
resolved_model = models.get_model(app_name, model_name)
- if not resolved_model:
- raise ValueError("Django did not return a model for "
- "{0}.{1}".format(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))
return resolved_model
elif inspect.isclass(obj) and issubclass(obj, models.Model):
return obj
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 0bdb36bb..8c286ea4 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -1,4 +1,5 @@
from __future__ import unicode_literals
+from django.core.exceptions import ImproperlyConfigured
from django.conf.urls import patterns, url
from django.test import TestCase
from django.utils import six
@@ -161,5 +162,5 @@ class ResolveModelWithPatchedDjangoTests(TestCase):
rest_framework.utils.model_meta.models.get_model = self.get_model
def test_blows_up_if_model_does_not_resolve(self):
- with self.assertRaises(ValueError):
+ with self.assertRaises(ImproperlyConfigured):
_resolve_model('tests.BasicModel')