This commit is contained in:
Tom Christie 2013-02-12 22:58:38 +00:00
parent 3f529dc25d
commit 724906c516

View File

@ -785,6 +785,23 @@ class RelatedTraversalTest(TestCase):
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):
def setUp(self):