Skip to content

Commit a3dc114

Browse files
committed
Add support for searchable Entry manager method.
1 parent 2bf75cd commit a3dc114

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

blog/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ def published(self):
3737
def active(self):
3838
return self.filter(is_active=True)
3939

40+
def searchable(self):
41+
return self.filter(is_searchable=True)
42+
4043

4144
class ContentFormat(models.TextChoices):
4245
REST = "reST", "reStructuredText"

blog/tests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,26 @@ def test_manager_published(self):
6565
transform=lambda entry: entry.headline,
6666
)
6767

68+
def test_manager_searchable(self):
69+
"""
70+
Make sure that the Entry manager's `searchable` method works
71+
"""
72+
Entry.objects.create(
73+
pub_date=self.yesterday,
74+
is_searchable=False,
75+
headline="not searchable",
76+
slug="a",
77+
)
78+
Entry.objects.create(
79+
pub_date=self.yesterday, is_searchable=True, headline="searchable", slug="b"
80+
)
81+
82+
self.assertQuerySetEqual(
83+
Entry.objects.searchable(),
84+
["searchable"],
85+
transform=lambda entry: entry.headline,
86+
)
87+
6888
def test_docutils_safe(self):
6989
"""
7090
Make sure docutils' file inclusion directives are disabled by default.

docs/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def _sync_blog_to_db(self):
229229
support end date.
230230
"""
231231
if self.lang == "en" and self.support_end:
232-
for entry in Entry.objects.published(self.support_end):
232+
for entry in Entry.objects.published(self.support_end).searchable():
233233
Document.objects.create(
234234
release=self,
235235
path=entry.get_absolute_url(),

0 commit comments

Comments
 (0)