Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 466198c4d95183c9ef8a41025945da24dfcbbd00 1 parent 014b961
@malcolmt malcolmt authored
Showing with 13 additions and 0 deletions.
  1. +13 −0 tests/modeltests/defer/models.py
View
13 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 @@ def count_delayed_fields(obj, debug=False):
# 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>]
+
+
"""}
Please sign in to comment.
Something went wrong with that request. Please try again.