aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/tests/genericrelations.py
diff options
context:
space:
mode:
authorTom Christie2012-10-04 22:07:24 +0100
committerTom Christie2012-10-04 22:07:24 +0100
commit693892ed0104b8ce8cd801e7bec6107feeb88782 (patch)
treeae049236abc6868c0b48803a04e8dc7cd4d5040c /rest_framework/tests/genericrelations.py
parentcc0d2601b8dfdf3f5fcee8591540b9cb4b2f3e44 (diff)
downloaddjango-rest-framework-693892ed0104b8ce8cd801e7bec6107feeb88782.tar.bz2
Fix for field to make it easier to access field relationships
Diffstat (limited to 'rest_framework/tests/genericrelations.py')
-rw-r--r--rest_framework/tests/genericrelations.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/rest_framework/tests/genericrelations.py b/rest_framework/tests/genericrelations.py
new file mode 100644
index 00000000..d88a6c06
--- /dev/null
+++ b/rest_framework/tests/genericrelations.py
@@ -0,0 +1,33 @@
+from django.test import TestCase
+from rest_framework import serializers
+from rest_framework.tests.models import *
+
+
+class TestGenericRelations(TestCase):
+ def setUp(self):
+ bookmark = Bookmark(url='https://www.djangoproject.com/')
+ bookmark.save()
+ django = Tag(tag_name='django')
+ django.save()
+ python = Tag(tag_name='python')
+ python.save()
+ t1 = TaggedItem(content_object=bookmark, tag=django)
+ t1.save()
+ t2 = TaggedItem(content_object=bookmark, tag=python)
+ t2.save()
+ self.bookmark = bookmark
+
+ def test_reverse_generic_relation(self):
+ class BookmarkSerializer(serializers.ModelSerializer):
+ tags = serializers.Field(source='tags')
+
+ class Meta:
+ model = Bookmark
+ exclude = ('id',)
+
+ serializer = BookmarkSerializer(instance=self.bookmark)
+ expected = {
+ 'tags': [u'django', u'python'],
+ 'url': u'https://www.djangoproject.com/'
+ }
+ self.assertEquals(serializer.data, expected)