summaryrefslogtreecommitdiff
path: root/django/db/models/sql/subqueries.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-01-29 10:46:36 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-01-29 10:46:36 +0000
commitcf37e4624a967f936ecbb5a4eefc9d38ed9d7892 (patch)
treee44fab9a21ccdf130d85b6fb80c423181663f103 /django/db/models/sql/subqueries.py
parent08dd4176edc1019d9168608b55fe777512c641cb (diff)
Fixed #7210 -- Added F() expressions to query language. See the documentation for details on usage.
Many thanks to: * Nicolas Lara, who worked on this feature during the 2008 Google Summer of Code. * Alex Gaynor for his help debugging and fixing a number of issues. * Malcolm Tredinnick for his invaluable review notes. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9792 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/sql/subqueries.py')
-rw-r--r--django/db/models/sql/subqueries.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/django/db/models/sql/subqueries.py b/django/db/models/sql/subqueries.py
index 0a59b403c8..f2589ea2b6 100644
--- a/django/db/models/sql/subqueries.py
+++ b/django/db/models/sql/subqueries.py
@@ -5,6 +5,7 @@ Query subclasses which provide extra functionality beyond simple data retrieval.
from django.core.exceptions import FieldError
from django.db.models.sql.constants import *
from django.db.models.sql.datastructures import Date
+from django.db.models.sql.expressions import SQLEvaluator
from django.db.models.sql.query import Query
from django.db.models.sql.where import AND, Constraint
@@ -136,7 +137,11 @@ class UpdateQuery(Query):
result.append('SET')
values, update_params = [], []
for name, val, placeholder in self.values:
- if val is not None:
+ if hasattr(val, 'as_sql'):
+ sql, params = val.as_sql(qn)
+ values.append('%s = %s' % (qn(name), sql))
+ update_params.extend(params)
+ elif val is not None:
values.append('%s = %s' % (qn(name), placeholder))
update_params.append(val)
else:
@@ -251,6 +256,8 @@ class UpdateQuery(Query):
else:
placeholder = '%s'
+ if hasattr(val, 'evaluate'):
+ val = SQLEvaluator(val, self, allow_joins=False)
if model:
self.add_related_update(model, field.column, val, placeholder)
else: