mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 19:43:59 +03:00
Test for #637.
This commit is contained in:
parent
3f529dc25d
commit
724906c516
|
@ -785,6 +785,23 @@ class RelatedTraversalTest(TestCase):
|
||||||
|
|
||||||
self.assertEqual(serializer.data, expected)
|
self.assertEqual(serializer.data, expected)
|
||||||
|
|
||||||
|
def test_queryset_nested_traversal(self):
|
||||||
|
"""
|
||||||
|
Relational fields should be able to use methods as their source.
|
||||||
|
"""
|
||||||
|
BlogPost.objects.create(title='blah')
|
||||||
|
|
||||||
|
class QuerysetMethodSerializer(serializers.Serializer):
|
||||||
|
blogposts = serializers.RelatedField(many=True, source='get_all_blogposts')
|
||||||
|
|
||||||
|
class ClassWithQuerysetMethod(object):
|
||||||
|
def get_all_blogposts(self):
|
||||||
|
return BlogPost.objects
|
||||||
|
|
||||||
|
obj = ClassWithQuerysetMethod()
|
||||||
|
serializer = QuerysetMethodSerializer(obj)
|
||||||
|
self.assertEquals(serializer.data, {'blogposts': [u'BlogPost object']})
|
||||||
|
|
||||||
|
|
||||||
class SerializerMethodFieldTests(TestCase):
|
class SerializerMethodFieldTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user