From 466198c4d95183c9ef8a41025945da24dfcbbd00 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Thu, 19 Mar 2009 22:46:28 +0000 Subject: [PATCH] Added a test for defer() / only() to make sure saving continues to work. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10092 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/defer/models.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/modeltests/defer/models.py b/tests/modeltests/defer/models.py index 1f515bc95e..ce65065d40 100644 --- a/tests/modeltests/defer/models.py +++ b/tests/modeltests/defer/models.py @@ -14,6 +14,9 @@ class Primary(models.Model): value = models.CharField(max_length=50) related = models.ForeignKey(Secondary) + def __unicode__(self): + return self.name + def count_delayed_fields(obj, debug=False): """ Returns the number of delayed attributes on the given model instance. @@ -86,4 +89,14 @@ Using defer() and only() with get() is also valid. # KNOWN NOT TO WORK: >>> count_delayed_fields(qs.only('name').select_related('related')[0]) # KNOWN NOT TO WORK >>> count_delayed_fields(qs.defer('related').select_related('related')[0]) +# Saving models with deferred fields is possible (but inefficient, since every +# field has to be retrieved first). + +>>> obj = Primary.objects.defer("value").get(name="p1") +>>> obj.name = "a new name" +>>> obj.save() +>>> Primary.objects.all() +[] + + """}