From b79702b2deec4ca3c625e5bffe46fa976c3c4e5f Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Sat, 24 Oct 2009 00:28:39 +0000 Subject: 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 --- django/forms/models.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'django/forms') 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) ]) -- cgit v1.3