mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
[soc2010/query-refactor] Fixed __isnull.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13380 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
1fda238ce8
commit
530434f7ba
@ -6,9 +6,9 @@ from django.db.models.sql.datastructures import FullResultSet
|
|||||||
# TODO: ...
|
# TODO: ...
|
||||||
class SQLCompiler(object):
|
class SQLCompiler(object):
|
||||||
LOOKUP_TYPES = {
|
LOOKUP_TYPES = {
|
||||||
"exact": lambda params: params[0],
|
"exact": lambda params, value_annotation, negated: params[0],
|
||||||
"lt": lambda params: {"$lt": params[0]},
|
"lt": lambda params, value_annotation, negated: {"$lt": params[0]},
|
||||||
"isnull": lambda params: params[0]
|
"isnull": lambda params, value_annotation, negated: {"$ne": None} if value_annotation == negated else None,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, query, connection, using):
|
def __init__(self, query, connection, using):
|
||||||
@ -49,7 +49,7 @@ class SQLCompiler(object):
|
|||||||
if column == self.query.model._meta.pk.column:
|
if column == self.query.model._meta.pk.column:
|
||||||
column = "_id"
|
column = "_id"
|
||||||
|
|
||||||
return column, self.LOOKUP_TYPES[lookup_type](params)
|
return column, self.LOOKUP_TYPES[lookup_type](params, value_annotation, negated)
|
||||||
|
|
||||||
def negate(self, k, v):
|
def negate(self, k, v):
|
||||||
if isinstance(v, dict):
|
if isinstance(v, dict):
|
||||||
|
@ -189,3 +189,38 @@ class MongoTestCase(TestCase):
|
|||||||
],
|
],
|
||||||
lambda g: g.name,
|
lambda g: g.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_isnull(self):
|
||||||
|
q = Group.objects.create(name="Queen", year_formed=1971)
|
||||||
|
e = Group.objects.create(name="The E Street Band", year_formed=1972)
|
||||||
|
b = Group.objects.create(name="The Beatles")
|
||||||
|
|
||||||
|
self.assertQuerysetEqual(
|
||||||
|
Group.objects.filter(year_formed__isnull=True), [
|
||||||
|
"The Beatles",
|
||||||
|
],
|
||||||
|
lambda g: g.name,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertQuerysetEqual(
|
||||||
|
Group.objects.filter(year_formed__isnull=False), [
|
||||||
|
"Queen",
|
||||||
|
"The E Street Band",
|
||||||
|
],
|
||||||
|
lambda g: g.name
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertQuerysetEqual(
|
||||||
|
Group.objects.exclude(year_formed__isnull=True), [
|
||||||
|
"Queen",
|
||||||
|
"The E Street Band",
|
||||||
|
],
|
||||||
|
lambda g: g.name
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertQuerysetEqual(
|
||||||
|
Group.objects.exclude(year_formed__isnull=False), [
|
||||||
|
"The Beatles",
|
||||||
|
],
|
||||||
|
lambda g: g.name
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user