summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2007-02-26 17:33:27 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2007-02-26 17:33:27 +0000
commit51f39d59bd42375e6ded28c2b6538e053d78b626 (patch)
tree3cbce152b3b34705a8e5df0d0c4be93154c7e49f /tests
parenta30e3fca48be23c856cda778ec3f0e0eec75fd91 (diff)
Fixed #3390: the serializer can now contain forward references. Thanks, Russ.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4610 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/serializers/models.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/modeltests/serializers/models.py b/tests/modeltests/serializers/models.py
index e24ff537c1..e86546c6fe 100644
--- a/tests/modeltests/serializers/models.py
+++ b/tests/modeltests/serializers/models.py
@@ -139,4 +139,24 @@ __test__ = {'API_TESTS':"""
... print obj
<DeserializedObject: Profile of Joe>
+# Objects ids can be referenced before they are defined in the serialization data
+# However, the deserialization process will need to be contained within a transaction
+>>> json = '[{"pk": "3", "model": "serializers.article", "fields": {"headline": "Forward references pose no problem", "pub_date": "2006-06-16 15:00:00", "categories": [4, 1], "author": 4}}, {"pk": "4", "model": "serializers.category", "fields": {"name": "Reference"}}, {"pk": "4", "model": "serializers.author", "fields": {"name": "Agnes"}}]'
+>>> from django.db import transaction
+>>> transaction.enter_transaction_management()
+>>> transaction.managed(True)
+>>> for obj in serializers.deserialize("json", json):
+... obj.save()
+
+>>> transaction.commit()
+>>> transaction.leave_transaction_management()
+
+>>> article = Article.objects.get(pk=3)
+>>> article
+<Article: Forward references pose no problem>
+>>> article.categories.all()
+[<Category: Reference>, <Category: Sports>]
+>>> article.author
+<Author: Agnes>
+
"""}