Author: mtredinnick
Date: 2009-03-19 17:46:28 -0500 (Thu, 19 Mar 2009)
New Revision: 10092

Modified:
   django/trunk/tests/modeltests/defer/models.py
Log:
Added a test for defer() / only() to make sure saving continues to work.

Modified: django/trunk/tests/modeltests/defer/models.py
===================================================================
--- django/trunk/tests/modeltests/defer/models.py       2009-03-19 09:43:45 UTC 
(rev 10091)
+++ django/trunk/tests/modeltests/defer/models.py       2009-03-19 22:46:28 UTC 
(rev 10092)
@@ -14,6 +14,9 @@
     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 @@
 # 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()
+[<Primary: a new name>]
+
+
 """}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to