mirror of
https://github.com/django/django.git
synced 2025-11-25 21:22:14 +00:00
Fixed #31340 -- Allowed query expressions in SearchQuery.value and __search lookup.
This commit is contained in:
parent
924c01ba09
commit
3baf92cf82
6 changed files with 43 additions and 4 deletions
|
|
@ -185,6 +185,17 @@ class Migration(migrations.Migration):
|
|||
},
|
||||
bases=None,
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='LineSavedSearch',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('line', models.ForeignKey('postgres_tests.Line', on_delete=models.CASCADE)),
|
||||
('query', models.CharField(max_length=100)),
|
||||
],
|
||||
options={
|
||||
'required_db_vendor': 'postgresql',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='AggregateTestModel',
|
||||
fields=[
|
||||
|
|
|
|||
|
|
@ -139,6 +139,11 @@ class Line(PostgreSQLModel):
|
|||
return self.dialogue or ''
|
||||
|
||||
|
||||
class LineSavedSearch(PostgreSQLModel):
|
||||
line = models.ForeignKey('Line', models.CASCADE)
|
||||
query = models.CharField(max_length=100)
|
||||
|
||||
|
||||
class RangesModel(PostgreSQLModel):
|
||||
ints = IntegerRangeField(blank=True, null=True)
|
||||
bigints = BigIntegerRangeField(blank=True, null=True)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ from django.db.models import F
|
|||
from django.test import modify_settings, skipUnlessDBFeature
|
||||
|
||||
from . import PostgreSQLSimpleTestCase, PostgreSQLTestCase
|
||||
from .models import Character, Line, Scene
|
||||
from .models import Character, Line, LineSavedSearch, Scene
|
||||
|
||||
try:
|
||||
from django.contrib.postgres.search import (
|
||||
|
|
@ -110,6 +110,18 @@ class SimpleSearchTest(GrailTestData, PostgreSQLTestCase):
|
|||
)
|
||||
self.assertSequenceEqual(searched, [self.verse2])
|
||||
|
||||
def test_search_with_F_expression(self):
|
||||
# Non-matching query.
|
||||
LineSavedSearch.objects.create(line=self.verse1, query='hearts')
|
||||
# Matching query.
|
||||
match = LineSavedSearch.objects.create(line=self.verse1, query='elbows')
|
||||
for query_expression in [F('query'), SearchQuery(F('query'))]:
|
||||
with self.subTest(query_expression):
|
||||
searched = LineSavedSearch.objects.filter(
|
||||
line__dialogue__search=query_expression,
|
||||
)
|
||||
self.assertSequenceEqual(searched, [match])
|
||||
|
||||
|
||||
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'})
|
||||
class SearchVectorFieldTest(GrailTestData, PostgreSQLTestCase):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue