mirror of
https://github.com/django/django.git
synced 2024-12-25 10:35:48 +00:00
Allow Query objects to be values in query filters. This already existed for
relations, but not for normal fields. The latter comes up naturally in some update statements. Refs #7095 git-svn-id: http://code.djangoproject.com/svn/django/trunk@7494 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
e07a457c00
commit
1bb8260084
@ -9,6 +9,7 @@ except ImportError:
|
|||||||
|
|
||||||
from django.db import get_creation_module
|
from django.db import get_creation_module
|
||||||
from django.db.models import signals
|
from django.db.models import signals
|
||||||
|
from django.db.models.query_utils import QueryWrapper
|
||||||
from django.dispatch import dispatcher
|
from django.dispatch import dispatcher
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core import validators
|
from django.core import validators
|
||||||
@ -226,6 +227,9 @@ class Field(object):
|
|||||||
|
|
||||||
def get_db_prep_lookup(self, lookup_type, value):
|
def get_db_prep_lookup(self, lookup_type, value):
|
||||||
"Returns field's value prepared for database lookup."
|
"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'):
|
if lookup_type in ('exact', 'regex', 'iregex', 'gt', 'gte', 'lt', 'lte', 'month', 'day', 'search'):
|
||||||
return [value]
|
return [value]
|
||||||
elif lookup_type in ('range', 'in'):
|
elif lookup_type in ('range', 'in'):
|
||||||
|
Loading…
Reference in New Issue
Block a user