Browse files

Allow Query objects to be values in query filters. This already exist…

…ed for

relations, but not for normal fields. The latter comes up naturally in some
update statements.

Refs #7095

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent e07a457 commit 1bb8260084e6a44308d4707c3568a4daa143dacd @malcolmt malcolmt committed Apr 28, 2008
Showing with 4 additions and 0 deletions.
  1. +4 −0 django/db/models/fields/
@@ -9,6 +9,7 @@
from django.db import get_creation_module
from django.db.models import signals
+from django.db.models.query_utils import QueryWrapper
from django.dispatch import dispatcher
from django.conf import settings
from django.core import validators
@@ -226,6 +227,9 @@ def get_db_prep_save(self, value):
def get_db_prep_lookup(self, lookup_type, value):
"Returns field's value prepared for database lookup."
+ if hasattr(value, 'as_sql'):
+ sql, params = value.as_sql()
+ return QueryWrapper(('(%s)' % sql), params)
if lookup_type in ('exact', 'regex', 'iregex', 'gt', 'gte', 'lt', 'lte', 'month', 'day', 'search'):
return [value]
elif lookup_type in ('range', 'in'):

0 comments on commit 1bb8260

Please sign in to comment.