Test ForeignKey with RelatedFields

pull/1889/merge
Karl Hobley 2015-07-13 12:02:50 +01:00 zatwierdzone przez Matt Westcott
rodzic 2b7eb9c3c4
commit 3bce07f26f
3 zmienionych plików z 43 dodań i 4 usunięć

Wyświetl plik

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('wagtailcore', '0001_squashed_0016_change_page_url_path_to_text_field'),
('searchtests', '0002_searchtest_tags'),
]
operations = [
migrations.AddField(
model_name='searchtestchild',
name='page',
field=models.ForeignKey(to='wagtailcore.Page', blank=True, null=True),
),
]

Wyświetl plik

@ -57,8 +57,14 @@ class SearchTest(models.Model, index.Indexed):
class SearchTestChild(SearchTest):
subtitle = models.CharField(max_length=255, null=True, blank=True)
extra_content = models.TextField()
page = models.ForeignKey('wagtailcore.Page', null=True, blank=True)
search_fields = SearchTest.search_fields + [
index.SearchField('subtitle', partial_match=True),
index.SearchField('extra_content'),
index.RelatedFields('page', [
index.SearchField('title', partial_match=True),
index.SearchField('search_description'),
index.FilterField('live'),
]),
]

Wyświetl plik

@ -749,7 +749,7 @@ class TestElasticSearchMapping(TestCase):
'name': {'type': 'string', 'include_in_all': True, 'index_analyzer': 'edgengram_analyzer'},
'slug_filter': {'index': 'not_analyzed', 'type': 'string', 'include_in_all': False},
}
}
},
}
}
}
@ -801,7 +801,7 @@ class TestElasticSearchMappingInheritance(TestCase):
self.es_mapping = ElasticSearchMapping(models.SearchTestChild)
# Create ES document
self.obj = models.SearchTestChild(title="Hello", subtitle="World")
self.obj = models.SearchTestChild(title="Hello", subtitle="World", page_id=1)
self.obj.save()
self.obj.tags.add("a tag")
@ -819,6 +819,14 @@ class TestElasticSearchMappingInheritance(TestCase):
# New
'extra_content': {'type': 'string', 'include_in_all': True},
'subtitle': {'type': 'string', 'include_in_all': True, 'index_analyzer': 'edgengram_analyzer'},
'page': {
'type': 'nested',
'properties': {
'title': {'type': 'string', 'include_in_all': True, 'index_analyzer': 'edgengram_analyzer'},
'search_description': {'type': 'string', 'include_in_all': True},
'live_filter': {'index': 'not_analyzed', 'type': 'boolean', 'include_in_all': False},
}
},
# Inherited
'pk': {'index': 'not_analyzed', 'type': 'string', 'store': 'yes', 'include_in_all': False},
@ -836,7 +844,7 @@ class TestElasticSearchMappingInheritance(TestCase):
'name': {'type': 'string', 'include_in_all': True, 'index_analyzer': 'edgengram_analyzer'},
'slug_filter': {'index': 'not_analyzed', 'type': 'string', 'include_in_all': False},
}
}
},
}
}
}
@ -862,13 +870,18 @@ class TestElasticSearchMappingInheritance(TestCase):
# New
'extra_content': '',
'subtitle': 'World',
'page': {
'title': 'Root',
'search_description': '',
'live_filter': True,
},
# Changed
'content_type': 'searchtests_searchtest_searchtests_searchtestchild',
# Inherited
'pk': str(self.obj.pk),
'_partials': ['Hello', 'World', 'a tag'],
'_partials': ['Hello', 'Root', 'World', 'a tag'],
'live_filter': False,
'published_date_filter': None,
'title': 'Hello',