Permalink
Browse files

[soc2010/query-refactor] Implement querying, thereby providing that u…

…pdate wasn't working (not fixed yet).

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13341 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent fe2bd63 commit 7ce89032b6d54072c1f622a84f479c7e50bd6f18 @alex alex committed Jun 9, 2010
Showing with 20 additions and 0 deletions.
  1. +13 −0 django/contrib/mongodb/compiler.py
  2. +7 −0 tests/regressiontests/mongodb/tests.py
@@ -45,6 +45,14 @@ def build_query(self):
filters = self.get_filters(self.query.where)
return self.connection.db[self.query.model._meta.db_table].find(filters)
+ def results_iter(self):
+ query = self.build_query()
+ for row in query:
+ yield tuple(
+ row[f.column if f is not self.query.model._meta.pk else "_id"]
+ for f in self.query.model._meta.fields
+ )
+
def has_results(self):
try:
self.build_query()[0]
@@ -62,4 +70,9 @@ def insert(self, return_id=False):
])
if self.query.model._meta.pk.column in values:
values["_id"] = values.pop(self.query.model._meta.pk.column)
+ if "_id" in values and not values["_id"]:
+ del values["_id"]
return self.connection.db[self.query.model._meta.db_table].insert(values)
+
+class SQLUpdateCompiler(SQLCompiler):
+ pass
@@ -9,6 +9,10 @@ def test_create(self):
self.assertTrue(b.pk is not None)
self.assertEqual(b.name, "Bruce Springsteen")
self.assertTrue(b.good)
+ b2 = Artist.objects.get(pk=b.pk)
+ self.assertEqual(b.pk, b2.pk)
+ self.assertEqual(b.name, b2.name)
+ self.assertEqual(b.good, b2.good)
def test_update(self):
l = Artist.objects.create(name="Lady Gaga", good=True)
@@ -18,3 +22,6 @@ def test_update(self):
l.good = False
l.save()
self.assertEqual(l.pk, pk)
+
+ l = Artist.objects.get(pk=pk)
+ self.assertTrue(not l.good)

0 comments on commit 7ce8903

Please sign in to comment.