diff options
author | Russell Keith-Magee <russell@keith-magee.com> | 2009-02-24 11:15:31 +0000 |
---|---|---|
committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-02-24 11:15:31 +0000 |
commit | 7d03ca9e86e366c2c369101621d011eb6ee8b2c2 (patch) | |
tree | 99fea1747897dc075e212e8acd5b8e7d04b4eb4c /tests/modeltests | |
parent | 28605a9c2665505c85561b4f33483cfd81718898 (diff) | |
download | django-7d03ca9e86e366c2c369101621d011eb6ee8b2c2.tar.gz |
Fixed #10161 -- Modified evaluation of query expressions to allow for operators that take the form of functions. This is mostly for the benefit of Oracle, but it should prove useful later on. Thanks to Ian for the report and feedback on the fix.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9898 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests')
-rw-r--r-- | tests/modeltests/expressions/models.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/tests/modeltests/expressions/models.py b/tests/modeltests/expressions/models.py index 4043f5ec34..f29767a9d1 100644 --- a/tests/modeltests/expressions/models.py +++ b/tests/modeltests/expressions/models.py @@ -37,14 +37,26 @@ __test__ = {'API_TESTS': """ >>> Company(name='Test GmbH', num_employees=32, num_chairs=1, ... ceo=Employee.objects.create(firstname='Max', lastname='Mustermann')).save() +>>> company_query = Company.objects.values('name','num_employees','num_chairs').order_by('name','num_employees','num_chairs') + # We can filter for companies where the number of employees is greater than the # number of chairs. +>>> company_query.filter(num_employees__gt=F('num_chairs')) +[{'num_chairs': 5, 'name': u'Example Inc.', 'num_employees': 2300}, {'num_chairs': 1, 'name': u'Test GmbH', 'num_employees': 32}] ->>> Company.objects.filter(num_employees__gt=F('num_chairs')) -[<Company: Example Inc.>, <Company: Test GmbH>] +# We can set one field to have the value of another field +# Make sure we have enough chairs +>>> _ = company_query.update(num_chairs=F('num_employees')) +>>> company_query +[{'num_chairs': 2300, 'name': u'Example Inc.', 'num_employees': 2300}, {'num_chairs': 3, 'name': u'Foobar Ltd.', 'num_employees': 3}, {'num_chairs': 32, 'name': u'Test GmbH', 'num_employees': 32}] -# The relation of a foreign key can become copied over to an other foreign key. +# We can perform arithmetic operations in expressions +# Make sure we have 2 spare chairs +>>> _ =company_query.update(num_chairs=F('num_employees')+2) +>>> company_query +[{'num_chairs': 2302, 'name': u'Example Inc.', 'num_employees': 2300}, {'num_chairs': 5, 'name': u'Foobar Ltd.', 'num_employees': 3}, {'num_chairs': 34, 'name': u'Test GmbH', 'num_employees': 32}] +# The relation of a foreign key can become copied over to an other foreign key. >>> Company.objects.update(point_of_contact=F('ceo')) 3 |