mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Thanks Mariusz Felisiak and Simon Charette for reviews.
This commit is contained in:
committed by
Mariusz Felisiak
parent
e46ca51c24
commit
8b040e3cbb
@@ -434,6 +434,13 @@ class TestQuerying(PostgreSQLTestCase):
|
||||
self.objs[:1],
|
||||
)
|
||||
|
||||
def test_index_annotation(self):
|
||||
qs = NullableIntegerArrayModel.objects.annotate(second=models.F('field__1'))
|
||||
self.assertCountEqual(
|
||||
qs.values_list('second', flat=True),
|
||||
[None, None, None, 3, 30],
|
||||
)
|
||||
|
||||
def test_overlap(self):
|
||||
self.assertSequenceEqual(
|
||||
NullableIntegerArrayModel.objects.filter(field__overlap=[1, 2]),
|
||||
@@ -495,6 +502,15 @@ class TestQuerying(PostgreSQLTestCase):
|
||||
self.objs[2:3],
|
||||
)
|
||||
|
||||
def test_slice_annotation(self):
|
||||
qs = NullableIntegerArrayModel.objects.annotate(
|
||||
first_two=models.F('field__0_2'),
|
||||
)
|
||||
self.assertCountEqual(
|
||||
qs.values_list('first_two', flat=True),
|
||||
[None, [1], [2], [2, 3], [20, 30]],
|
||||
)
|
||||
|
||||
def test_usage_in_subquery(self):
|
||||
self.assertSequenceEqual(
|
||||
NullableIntegerArrayModel.objects.filter(
|
||||
|
||||
@@ -2,7 +2,7 @@ import json
|
||||
|
||||
from django.core import checks, exceptions, serializers
|
||||
from django.db import connection
|
||||
from django.db.models import OuterRef, Subquery
|
||||
from django.db.models import F, OuterRef, Subquery
|
||||
from django.db.models.expressions import RawSQL
|
||||
from django.forms import Form
|
||||
from django.test.utils import CaptureQueriesContext, isolate_apps
|
||||
@@ -137,6 +137,13 @@ class TestQuerying(PostgreSQLTestCase):
|
||||
self.objs[:2]
|
||||
)
|
||||
|
||||
def test_key_transform_annotation(self):
|
||||
qs = HStoreModel.objects.annotate(a=F('field__a'))
|
||||
self.assertCountEqual(
|
||||
qs.values_list('a', flat=True),
|
||||
['b', 'b', None, None, None],
|
||||
)
|
||||
|
||||
def test_keys(self):
|
||||
self.assertSequenceEqual(
|
||||
HStoreModel.objects.filter(field__keys=['a']),
|
||||
|
||||
Reference in New Issue
Block a user