summaryrefslogtreecommitdiff
path: root/django/forms/models.py
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2009-10-24 00:28:39 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2009-10-24 00:28:39 +0000
commitb79702b2deec4ca3c625e5bffe46fa976c3c4e5f (patch)
tree2031b1d908ca03f650669b04effee8a872632e86 /django/forms/models.py
parent9f70783b149105dfd37027504976f9526caeeae0 (diff)
Fixed #11402: added a `QuerySet.exists()` method. Thanks, Alex Gaynor.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11646 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/forms/models.py')
-rw-r--r--django/forms/models.py8
1 files changed, 2 insertions, 6 deletions
diff --git a/django/forms/models.py b/django/forms/models.py
index cc43612bf5..37fce6824c 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -319,9 +319,7 @@ class BaseModelForm(BaseForm):
if self.instance.pk is not None:
qs = qs.exclude(pk=self.instance.pk)
- # This cute trick with extra/values is the most efficient way to
- # tell if a particular query returns any results.
- if qs.extra(select={'a': 1}).values('a').order_by():
+ if qs.exists():
if len(unique_check) == 1:
self._errors[unique_check[0]] = ErrorList([self.unique_error_message(unique_check)])
else:
@@ -354,9 +352,7 @@ class BaseModelForm(BaseForm):
if self.instance.pk is not None:
qs = qs.exclude(pk=self.instance.pk)
- # This cute trick with extra/values is the most efficient way to
- # tell if a particular query returns any results.
- if qs.extra(select={'a': 1}).values('a').order_by():
+ if qs.exists():
self._errors[field] = ErrorList([
self.date_error_message(lookup_type, field, unique_for)
])