mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Removed some unnecessary __exact operators in filters.
This commit is contained in:
parent
298a2b577f
commit
b87c59b04b
@ -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(),
|
||||
|
@ -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 ''
|
||||
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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})
|
||||
|
@ -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
|
||||
# ...
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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 <lookups-that-span-relationships>`::
|
||||
|
||||
>>> Article.objects.filter(publications__id__exact=1)
|
||||
>>> Article.objects.filter(publications__id=1)
|
||||
[<Article: Django lets you build Web apps easily>, <Article: NASA uses Python>]
|
||||
>>> Article.objects.filter(publications__pk=1)
|
||||
[<Article: Django lets you build Web apps easily>, <Article: NASA uses Python>]
|
||||
@ -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: The Python Journal>]
|
||||
>>> Publication.objects.filter(pk=1)
|
||||
[<Publication: The Python Journal>]
|
||||
@ -151,7 +151,7 @@ a :class:`~django.db.models.ManyToManyField`)::
|
||||
>>> Publication.objects.filter(article__headline__startswith="NASA")
|
||||
[<Publication: Highlights for Children>, <Publication: Science News>, <Publication: Science Weekly>, <Publication: The Python Journal>]
|
||||
|
||||
>>> Publication.objects.filter(article__id__exact=1)
|
||||
>>> Publication.objects.filter(article__id=1)
|
||||
[<Publication: The Python Journal>]
|
||||
>>> Publication.objects.filter(article__pk=1)
|
||||
[<Publication: The Python Journal>]
|
||||
|
@ -123,7 +123,7 @@ This works as many levels deep as you want. There's no limit. For example::
|
||||
[<Article: This is a test>]
|
||||
|
||||
# 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')
|
||||
[<Article: John's second story>, <Article: This is a test>]
|
||||
|
||||
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')
|
||||
[<Article: John's second story>, <Article: This is a test>]
|
||||
|
||||
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: John Smith>, <Reporter: John Smith>, <Reporter: John Smith>, <Reporter: John Smith>]
|
||||
>>> Reporter.objects.filter(article__reporter__first_name__startswith='John').distinct()
|
||||
[<Reporter: John Smith>]
|
||||
>>> Reporter.objects.filter(article__reporter__exact=r).distinct()
|
||||
>>> Reporter.objects.filter(article__reporter=r).distinct()
|
||||
[<Reporter: John Smith>]
|
||||
|
||||
If you delete a reporter, his articles will be deleted (assuming that the
|
||||
|
@ -113,7 +113,7 @@ This of course works in reverse::
|
||||
|
||||
>>> Place.objects.get(pk=1)
|
||||
<Place: Demon Dogs the place>
|
||||
>>> Place.objects.get(restaurant__place__exact=p1)
|
||||
>>> Place.objects.get(restaurant__place=p1)
|
||||
<Place: Demon Dogs the place>
|
||||
>>> Place.objects.get(restaurant=r)
|
||||
<Place: Demon Dogs the place>
|
||||
|
@ -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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user