summaryrefslogtreecommitdiff
path: root/tests/modeltests/expressions/models.py
diff options
context:
space:
mode:
authorKevin Kubasik <kevin@kubasik.net>2009-08-04 09:30:09 +0000
committerKevin Kubasik <kevin@kubasik.net>2009-08-04 09:30:09 +0000
commite2d14c075a51eb1f0b832765df8723d82f0afac4 (patch)
treeca4e9e95cb45d9275f6272b8ca1bab7f06e5eeff /tests/modeltests/expressions/models.py
parentf0a864b482cb3aad69424e33a7e259ddb831ea5f (diff)
parentcb5e5dc2bc232905c03deea6bc453a2e9a2338f1 (diff)
[gsoc2009-testing] Massive merge update to trunk. This is in preparation for the release of a sample app and tests
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/test-improvements@11385 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests/expressions/models.py')
-rw-r--r--tests/modeltests/expressions/models.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/modeltests/expressions/models.py b/tests/modeltests/expressions/models.py
index f29767a9d1..d4de5ccee9 100644
--- a/tests/modeltests/expressions/models.py
+++ b/tests/modeltests/expressions/models.py
@@ -80,4 +80,43 @@ Traceback (most recent call last):
...
FieldError: Joined field references are not permitted in this query
+# F expressions can be used to update attributes on single objects
+>>> test_gmbh = Company.objects.get(name='Test GmbH')
+>>> test_gmbh.num_employees
+32
+>>> test_gmbh.num_employees = F('num_employees') + 4
+>>> test_gmbh.save()
+>>> test_gmbh = Company.objects.get(pk=test_gmbh.pk)
+>>> test_gmbh.num_employees
+36
+
+# F expressions cannot be used to update attributes which are foreign keys, or
+# attributes which involve joins.
+>>> test_gmbh.point_of_contact = None
+>>> test_gmbh.save()
+>>> test_gmbh.point_of_contact is None
+True
+>>> test_gmbh.point_of_contact = F('ceo')
+Traceback (most recent call last):
+...
+ValueError: Cannot assign "<django.db.models.expressions.F object at ...>": "Company.point_of_contact" must be a "Employee" instance.
+
+>>> test_gmbh.point_of_contact = test_gmbh.ceo
+>>> test_gmbh.save()
+>>> test_gmbh.name = F('ceo__last_name')
+>>> test_gmbh.save()
+Traceback (most recent call last):
+...
+FieldError: Joined field references are not permitted in this query
+
+# F expressions cannot be used to update attributes on objects which do not yet
+# exist in the database
+>>> acme = Company(name='The Acme Widget Co.', num_employees=12, num_chairs=5,
+... ceo=test_gmbh.ceo)
+>>> acme.num_employees = F('num_employees') + 16
+>>> acme.save()
+Traceback (most recent call last):
+...
+TypeError: int() argument must be a string or a number, not 'ExpressionNode'
+
"""}