Ticket #10516: 10516_fix.diff
File 10516_fix.diff, 5.4 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/views/main.py
229 229 if self.search_fields and self.query: 230 230 for bit in self.query.split(): 231 231 or_queries = [models.Q(**{construct_search(str(field_name)): bit}) for field_name in self.search_fields] 232 other_qs = QuerySet(self.model) 233 other_qs.dup_select_related(qs) 234 other_qs = other_qs.filter(reduce(operator.or_, or_queries)) 235 qs = qs & other_qs 232 qs = qs.filter(reduce(operator.or_, or_queries)) 236 233 for field_name in self.search_fields: 237 234 if '__' in field_name: 238 235 qs = qs.distinct() -
tests/regressiontests/admin_views/fixtures/multiple-child-classes.json
1 [{"pk": 1, "model": "admin_views.title", "fields": {}}, {"pk": 2, "model": "admin_views.title", "fields": {}}, {"pk": 3, "model": "admin_views.title", "fields": {}}, {"pk": 4, "model": "admin_views.title", "fields": {}}, {"pk": 1, "model": "admin_views.titletranslation", "fields": {"text": "Bar", "title": 1}}, {"pk": 2, "model": "admin_views.titletranslation", "fields": {"text": "Foo", "title": 2}}, {"pk": 3, "model": "admin_views.titletranslation", "fields": {"text": "Few", "title": 3}}, {"pk": 4, "model": "admin_views.titletranslation", "fields": {"text": "Bas", "title": 4}}, {"pk": 1, "model": "admin_views.recommender", "fields": {}}, {"pk": 4, "model": "admin_views.recommender", "fields": {}}, {"pk": 2, "model": "admin_views.recommendation", "fields": {"recommender": 1}}, {"pk": 3, "model": "admin_views.recommendation", "fields": {"recommender": 4}}] -
tests/regressiontests/admin_views/tests.py
865 865 866 866 self.failUnlessEqual(Person.objects.get(name="John Mauchly").alive, False) 867 867 868 class AdminSearchOnSiblingModels(TestCase): 869 fixtures = ['admin-views-users','multiple-child-classes'] 870 871 def setUp(self): 872 self.client.login(username='super', password='secret') 873 874 def tearDown(self): 875 self.client.logout() 876 877 def test_something(self): 878 response = self.client.get('/test_admin/admin/admin_views/recommendation/?q=bar') 879 880 # confirm the search returned 1 object 881 self.assert_("\n1 recommendation\n" in response.content) 882 868 883 class AdminInheritedInlinesTest(TestCase): 869 884 fixtures = ['admin-views-users.xml',] 870 885 -
tests/regressiontests/admin_views/models.py
325 325 class PictureAdmin(admin.ModelAdmin): 326 326 pass 327 327 328 # a base class for Recommender and Recommendation 329 class Title(models.Model): 330 pass 331 332 class TitleTranslation(models.Model): 333 title = models.ForeignKey(Title) 334 text = models.CharField(max_length=100) 335 336 class Recommender(Title): 337 pass 338 339 class Recommendation(Title): 340 recommender = models.ForeignKey(Recommender) 341 342 class RecommendationAdmin(admin.ModelAdmin): 343 search_fields = ('titletranslation__text', 'recommender__titletranslation__text',) 344 345 328 346 admin.site.register(Article, ArticleAdmin) 329 347 admin.site.register(CustomArticle, CustomArticleAdmin) 330 348 admin.site.register(Section, save_as=True, inlines=[ArticleInline]) … … 343 361 admin.site.register(Fabric, FabricAdmin) 344 362 admin.site.register(Gallery, GalleryAdmin) 345 363 admin.site.register(Picture, PictureAdmin) 364 admin.site.register(Recommendation, RecommendationAdmin) 365 admin.site.register(Recommender) 346 366 347 367 # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2. 348 368 # That way we cover all four cases: -
tests/regressiontests/admin_views/fixtures/multiple-child-classes.json
1 [{"pk": 1, "model": "admin_views.title", "fields": {}}, {"pk": 2, "model": "admin_views.title", "fields": {}}, {"pk": 3, "model": "admin_views.title", "fields": {}}, {"pk": 4, "model": "admin_views.title", "fields": {}}, {"pk": 1, "model": "admin_views.titletranslation", "fields": {"text": "Bar", "title": 1}}, {"pk": 2, "model": "admin_views.titletranslation", "fields": {"text": "Foo", "title": 2}}, {"pk": 3, "model": "admin_views.titletranslation", "fields": {"text": "Few", "title": 3}}, {"pk": 4, "model": "admin_views.titletranslation", "fields": {"text": "Bas", "title": 4}}, {"pk": 1, "model": "admin_views.recommender", "fields": {}}, {"pk": 4, "model": "admin_views.recommender", "fields": {}}, {"pk": 2, "model": "admin_views.recommendation", "fields": {"recommender": 1}}, {"pk": 3, "model": "admin_views.recommendation", "fields": {"recommender": 4}}]