summaryrefslogtreecommitdiff
path: root/tests/get_object_or_404
diff options
context:
space:
mode:
authormgaligniana <marcelogaligniana@gmail.com>2021-11-22 16:30:07 -0300
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-11-24 09:28:21 +0100
commit7f8f69fb38247827220805f18c2e0f08406d8a3b (patch)
tree92f8918f0c32e7c2a558f5657dd997dd60b4b1b0 /tests/get_object_or_404
parentddf321479b0e006bc4efafe57726d54869f38c14 (diff)
downloaddjango-7f8f69fb38247827220805f18c2e0f08406d8a3b.tar.gz
Fixed #33298 -- Added docs and tests for using Q objects with get_object_or_404()/get_list_or_404().
Diffstat (limited to 'tests/get_object_or_404')
-rw-r--r--tests/get_object_or_404/tests.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/get_object_or_404/tests.py b/tests/get_object_or_404/tests.py
index 71815d34ef..87bfa6d3ea 100644
--- a/tests/get_object_or_404/tests.py
+++ b/tests/get_object_or_404/tests.py
@@ -1,3 +1,4 @@
+from django.db.models import Q
from django.http import Http404
from django.shortcuts import get_list_or_404, get_object_or_404
from django.test import TestCase
@@ -75,6 +76,23 @@ class GetObjectOr404Tests(TestCase):
get_list_or_404(Article.objects.all(), title__icontains="Run"),
[article]
)
+ # Q objects.
+ self.assertEqual(
+ get_object_or_404(
+ Article,
+ Q(title__startswith='Run') | Q(title__startswith='Walk'),
+ authors__name__contains='Brave',
+ ),
+ article,
+ )
+ self.assertEqual(
+ get_list_or_404(
+ Article,
+ Q(title__startswith='Run') | Q(title__startswith='Walk'),
+ authors__name='Patsy',
+ ),
+ [article],
+ )
def test_bad_class(self):
# Given an argument klass that is not a Model, Manager, or Queryset