From b87c59b04bc549a5ba42023d04e4be7a4737f7d9 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Fri, 17 Jan 2014 17:27:04 -0500 Subject: [PATCH] Removed some unnecessary __exact operators in filters. --- django/contrib/admin/options.py | 2 +- django/contrib/admin/templatetags/log.py | 2 +- django/contrib/contenttypes/generic.py | 2 +- django/contrib/flatpages/views.py | 4 ++-- django/contrib/sites/managers.py | 2 +- docs/ref/contrib/sites.txt | 2 +- docs/topics/auth/default.txt | 2 +- docs/topics/db/examples/many_to_many.txt | 6 +++--- docs/topics/db/examples/many_to_one.txt | 6 +++--- docs/topics/db/examples/one_to_one.txt | 2 +- docs/topics/db/queries.txt | 4 ++-- 11 files changed, 17 insertions(+), 17 deletions(-) diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 263d1f4a87..0f2404bf40 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -1620,7 +1620,7 @@ class ModelAdmin(BaseModelAdmin): app_label = opts.app_label action_list = LogEntry.objects.filter( object_id=unquote(object_id), - content_type__id__exact=ContentType.objects.get_for_model(model).id + content_type=ContentType.objects.get_for_model(model) ).select_related().order_by('action_time') context = dict(self.admin_site.each_context(), diff --git a/django/contrib/admin/templatetags/log.py b/django/contrib/admin/templatetags/log.py index 7605d7f7fe..01b54c29c7 100644 --- a/django/contrib/admin/templatetags/log.py +++ b/django/contrib/admin/templatetags/log.py @@ -18,7 +18,7 @@ class AdminLogNode(template.Node): user_id = self.user if not user_id.isdigit(): user_id = context[self.user].pk - context[self.varname] = LogEntry.objects.filter(user__pk__exact=user_id).select_related('content_type', 'user')[:int(self.limit)] + context[self.varname] = LogEntry.objects.filter(user__pk=user_id).select_related('content_type', 'user')[:int(self.limit)] return '' diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py index 1ec5475f5b..a92f0f0dc8 100644 --- a/django/contrib/contenttypes/generic.py +++ b/django/contrib/contenttypes/generic.py @@ -324,7 +324,7 @@ def create_generic_related_manager(superclass): self.pk_val = self.instance._get_pk_val() self.core_filters = { '%s__pk' % content_type_field_name: content_type.id, - '%s__exact' % object_id_field_name: instance._get_pk_val(), + '%s' % object_id_field_name: instance._get_pk_val(), } def __call__(self, **kwargs): diff --git a/django/contrib/flatpages/views.py b/django/contrib/flatpages/views.py index 0f87c90bfe..117fbb6f55 100644 --- a/django/contrib/flatpages/views.py +++ b/django/contrib/flatpages/views.py @@ -35,12 +35,12 @@ def flatpage(request, url): site_id = get_current_site(request).id try: f = get_object_or_404(FlatPage, - url__exact=url, sites__id__exact=site_id) + url=url, sites=site_id) except Http404: if not url.endswith('/') and settings.APPEND_SLASH: url += '/' f = get_object_or_404(FlatPage, - url__exact=url, sites__id__exact=site_id) + url=url, sites=site_id) return HttpResponsePermanentRedirect('%s/' % request.path) else: raise diff --git a/django/contrib/sites/managers.py b/django/contrib/sites/managers.py index 9cdc1ed413..173f439775 100644 --- a/django/contrib/sites/managers.py +++ b/django/contrib/sites/managers.py @@ -39,4 +39,4 @@ class CurrentSiteManager(models.Manager): def get_queryset(self): if not self.__is_validated: self._validate_field_name() - return super(CurrentSiteManager, self).get_queryset().filter(**{self.__field_name + '__id__exact': settings.SITE_ID}) + return super(CurrentSiteManager, self).get_queryset().filter(**{self.__field_name + '__id': settings.SITE_ID}) diff --git a/docs/ref/contrib/sites.txt b/docs/ref/contrib/sites.txt index 24b6294278..80473c59aa 100644 --- a/docs/ref/contrib/sites.txt +++ b/docs/ref/contrib/sites.txt @@ -84,7 +84,7 @@ This accomplishes several things quite nicely: def article_detail(request, article_id): try: - a = Article.objects.get(id=article_id, sites__id__exact=get_current_site(request).id) + a = Article.objects.get(id=article_id, sites__id=get_current_site(request).id) except Article.DoesNotExist: raise Http404 # ... diff --git a/docs/topics/auth/default.txt b/docs/topics/auth/default.txt index 2c0ce45482..247f5a38f1 100644 --- a/docs/topics/auth/default.txt +++ b/docs/topics/auth/default.txt @@ -101,7 +101,7 @@ You can also change a password programmatically, using .. code-block:: python >>> from django.contrib.auth.models import User - >>> u = User.objects.get(username__exact='john') + >>> u = User.objects.get(username='john') >>> u.set_password('new password') >>> u.save() diff --git a/docs/topics/db/examples/many_to_many.txt b/docs/topics/db/examples/many_to_many.txt index 5b06cde6f6..d127b93b0a 100644 --- a/docs/topics/db/examples/many_to_many.txt +++ b/docs/topics/db/examples/many_to_many.txt @@ -111,7 +111,7 @@ Create and add a ``Publication`` to an ``Article`` in one step using Many-to-many relationships can be queried using :ref:`lookups across relationships `:: - >>> Article.objects.filter(publications__id__exact=1) + >>> Article.objects.filter(publications__id=1) [, ] >>> Article.objects.filter(publications__pk=1) [, ] @@ -143,7 +143,7 @@ The :meth:`~django.db.models.query.QuerySet.count` function respects Reverse m2m queries are supported (i.e., starting at the table that doesn't have a :class:`~django.db.models.ManyToManyField`):: - >>> Publication.objects.filter(id__exact=1) + >>> Publication.objects.filter(id=1) [] >>> Publication.objects.filter(pk=1) [] @@ -151,7 +151,7 @@ a :class:`~django.db.models.ManyToManyField`):: >>> Publication.objects.filter(article__headline__startswith="NASA") [, , , ] - >>> Publication.objects.filter(article__id__exact=1) + >>> Publication.objects.filter(article__id=1) [] >>> Publication.objects.filter(article__pk=1) [] diff --git a/docs/topics/db/examples/many_to_one.txt b/docs/topics/db/examples/many_to_one.txt index af112144b3..983bc2eed4 100644 --- a/docs/topics/db/examples/many_to_one.txt +++ b/docs/topics/db/examples/many_to_one.txt @@ -123,7 +123,7 @@ This works as many levels deep as you want. There's no limit. For example:: [] # Find all Articles for any Reporter whose first name is "John". - >>> Article.objects.filter(reporter__first_name__exact='John') + >>> Article.objects.filter(reporter__first_name='John') [, ] Exact match is implied here:: @@ -134,7 +134,7 @@ Exact match is implied here:: Query twice over the related field. This translates to an AND condition in the WHERE clause:: - >>> Article.objects.filter(reporter__first_name__exact='John', reporter__last_name__exact='Smith') + >>> Article.objects.filter(reporter__first_name='John', reporter__last_name='Smith') [, ] For the related lookup you can supply a primary key value or pass the related @@ -184,7 +184,7 @@ Queries can go round in circles:: [, , , ] >>> Reporter.objects.filter(article__reporter__first_name__startswith='John').distinct() [] - >>> Reporter.objects.filter(article__reporter__exact=r).distinct() + >>> Reporter.objects.filter(article__reporter=r).distinct() [] If you delete a reporter, his articles will be deleted (assuming that the diff --git a/docs/topics/db/examples/one_to_one.txt b/docs/topics/db/examples/one_to_one.txt index a86e5ed0ac..994794c43b 100644 --- a/docs/topics/db/examples/one_to_one.txt +++ b/docs/topics/db/examples/one_to_one.txt @@ -113,7 +113,7 @@ This of course works in reverse:: >>> Place.objects.get(pk=1) - >>> Place.objects.get(restaurant__place__exact=p1) + >>> Place.objects.get(restaurant__place=p1) >>> Place.objects.get(restaurant=r) diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt index 7b38dbaea3..7f04c66fcb 100644 --- a/docs/topics/db/queries.txt +++ b/docs/topics/db/queries.txt @@ -411,7 +411,7 @@ can specify the field name suffixed with ``_id``. In this case, the value parameter is expected to contain the raw value of the foreign model's primary key. For example: - >>> Entry.objects.filter(blog_id__exact=4) + >>> Entry.objects.filter(blog_id=4) If you pass an invalid keyword argument, a lookup function will raise ``TypeError``. @@ -489,7 +489,7 @@ want. This example retrieves all ``Entry`` objects with a ``Blog`` whose ``name`` is ``'Beatles Blog'``:: - >>> Entry.objects.filter(blog__name__exact='Beatles Blog') + >>> Entry.objects.filter(blog__name='Beatles Blog') This spanning can be as deep as you'd like.