1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

[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
This commit is contained in:
Alex Gaynor 2010-06-09 19:59:44 +00:00
parent 7ce89032b6
commit 28499bbe36
3 changed files with 14 additions and 2 deletions

View File

@ -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
)

View File

@ -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):

View File

@ -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):
"""