diff options
| author | Alex Gaynor <alex.gaynor@gmail.com> | 2010-06-09 19:59:44 +0000 |
|---|---|---|
| committer | Alex Gaynor <alex.gaynor@gmail.com> | 2010-06-09 19:59:44 +0000 |
| commit | 28499bbe36c36fecf81cb8369fcb01efdc6f7160 (patch) | |
| tree | c82f0cc2a86df56dd00f16bdd4e3802f5e2314b5 /django | |
| parent | 7ce89032b6d54072c1f622a84f479c7e50bd6f18 (diff) | |
[soc2010/query-refactor] Fixed update on MongoDB.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13342 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/mongodb/compiler.py | 11 | ||||
| -rw-r--r-- | django/db/models/query.py | 2 | ||||
| -rw-r--r-- | django/db/models/sql/compiler.py | 3 |
3 files changed, 14 insertions, 2 deletions
diff --git a/django/contrib/mongodb/compiler.py b/django/contrib/mongodb/compiler.py index d7a100eaef..045f47504d 100644 --- a/django/contrib/mongodb/compiler.py +++ b/django/contrib/mongodb/compiler.py @@ -75,4 +75,13 @@ class SQLInsertCompiler(SQLCompiler): return self.connection.db[self.query.model._meta.db_table].insert(values) class SQLUpdateCompiler(SQLCompiler): - pass + def update(self, result_type): + # TODO: more asserts + filters = self.get_filters(self.query.where) + # TODO: Don't use set for everything, use INC and such where + # appropriate. + return self.connection.db[self.query.model._meta.db_table].update( + filters, + {"$set": dict((f.column, val) for f, o, val in self.query.values)}, + multi=True + ) diff --git a/django/db/models/query.py b/django/db/models/query.py index 812e1c82b7..958e8bdbc0 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -488,7 +488,7 @@ class QuerySet(object): query = self.query.clone(sql.UpdateQuery) query.add_update_fields(values) self._result_cache = None - return query.get_compiler(self.db).execute_sql(None) + return query.get_compiler(self.db).update(None) _update.alters_data = True def exists(self): diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 393efc1b3f..1cd5cb535b 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -866,6 +866,9 @@ class SQLUpdateCompiler(SQLCompiler): if where: result.append('WHERE %s' % where) return ' '.join(result), tuple(update_params + params) + + def update(self, *args, **kwargs): + return self.execute_sql(*args, **kwargs) def execute_sql(self, result_type): """ |
