mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #15961 -- Modified ModelAdmin to allow for custom search methods.
This adds a get_search_results method that users can override to provide custom search strategies. Thanks to Daniele Procida for help with the docs.
This commit is contained in:
parent
b06f6c1618
commit
2d309a7043
7 changed files with 109 additions and 30 deletions
|
@ -46,7 +46,7 @@ from .models import (Article, BarAccount, CustomArticle, EmptyModel, FooAccount,
|
|||
DooHickey, FancyDoodad, Whatsit, Category, Post, Plot, FunkyTag, Chapter,
|
||||
Book, Promo, WorkHour, Employee, Question, Answer, Inquisition, Actor,
|
||||
FoodDelivery, RowLevelChangePermissionModel, Paper, CoverLetter, Story,
|
||||
OtherStory, ComplexSortedPerson, Parent, Child, AdminOrderedField,
|
||||
OtherStory, ComplexSortedPerson, PluggableSearchPerson, Parent, Child, AdminOrderedField,
|
||||
AdminOrderedModelMethod, AdminOrderedAdminMethod, AdminOrderedCallable,
|
||||
Report, MainPrepopulated, RelatedPrepopulated, UnorderedObject,
|
||||
Simple, UndeletableObject, Choice, ShortMessage, Telegram)
|
||||
|
@ -2202,6 +2202,20 @@ class AdminSearchTest(TestCase):
|
|||
self.assertContains(response, "\n0 persons\n")
|
||||
self.assertNotContains(response, "Guido")
|
||||
|
||||
def test_pluggable_search(self):
|
||||
p1 = PluggableSearchPerson.objects.create(name="Bob", age=10)
|
||||
p2 = PluggableSearchPerson.objects.create(name="Amy", age=20)
|
||||
|
||||
response = self.client.get('/test_admin/admin/admin_views/pluggablesearchperson/?q=Bob')
|
||||
# confirm the search returned one object
|
||||
self.assertContains(response, "\n1 pluggable search person\n")
|
||||
self.assertContains(response, "Bob")
|
||||
|
||||
response = self.client.get('/test_admin/admin/admin_views/pluggablesearchperson/?q=20')
|
||||
# confirm the search returned one object
|
||||
self.assertContains(response, "\n1 pluggable search person\n")
|
||||
self.assertContains(response, "Amy")
|
||||
|
||||
|
||||
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||
class AdminInheritedInlinesTest(TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue