mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-09 08:00:52 +03:00
Fix _resolve_model to work with unicode strings
This commit is contained in:
parent
01e2a34210
commit
807f7a6bb9
|
@ -49,7 +49,7 @@ def _resolve_model(obj):
|
|||
String representations should have the format:
|
||||
'appname.ModelName'
|
||||
"""
|
||||
if type(obj) == str and len(obj.split('.')) == 2:
|
||||
if isinstance(obj, six.string_types) and len(obj.split('.')) == 2:
|
||||
app_name, model_name = obj.split('.')
|
||||
return models.get_model(app_name, model_name)
|
||||
elif inspect.isclass(obj) and issubclass(obj, models.Model):
|
||||
|
|
|
@ -3,6 +3,7 @@ from django.test import TestCase
|
|||
|
||||
from rest_framework.serializers import _resolve_model
|
||||
from rest_framework.tests.models import BasicModel
|
||||
from rest_framework.compat import six
|
||||
|
||||
|
||||
class ResolveModelTests(TestCase):
|
||||
|
@ -19,6 +20,10 @@ class ResolveModelTests(TestCase):
|
|||
resolved_model = _resolve_model('tests.BasicModel')
|
||||
self.assertEqual(resolved_model, BasicModel)
|
||||
|
||||
def test_resolve_unicode_representation(self):
|
||||
resolved_model = _resolve_model(six.text_type('tests.BasicModel'))
|
||||
self.assertEqual(resolved_model, BasicModel)
|
||||
|
||||
def test_resolve_non_django_model(self):
|
||||
with self.assertRaises(ValueError):
|
||||
_resolve_model(TestCase)
|
||||
|
|
Loading…
Reference in New Issue
Block a user