Ticket #10516: 10516_fix.diff

File 10516_fix.diff, 5.4 KB (added by Zain Memon, 16 years ago)

fix + tests

  • django/contrib/admin/views/main.py

     
    229229        if self.search_fields and self.query:
    230230            for bit in self.query.split():
    231231                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))
    236233            for field_name in self.search_fields:
    237234                if '__' in field_name:
    238235                    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

     
    865865
    866866        self.failUnlessEqual(Person.objects.get(name="John Mauchly").alive, False)
    867867
     868class 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
    868883class AdminInheritedInlinesTest(TestCase):
    869884    fixtures = ['admin-views-users.xml',]
    870885
  • tests/regressiontests/admin_views/models.py

     
    325325class PictureAdmin(admin.ModelAdmin):
    326326    pass
    327327
     328# a base class for Recommender and Recommendation
     329class Title(models.Model):
     330    pass
     331
     332class TitleTranslation(models.Model):
     333    title = models.ForeignKey(Title)
     334    text = models.CharField(max_length=100)
     335
     336class Recommender(Title):
     337    pass
     338
     339class Recommendation(Title):
     340    recommender = models.ForeignKey(Recommender)
     341
     342class RecommendationAdmin(admin.ModelAdmin):
     343    search_fields = ('titletranslation__text', 'recommender__titletranslation__text',)
     344
     345
    328346admin.site.register(Article, ArticleAdmin)
    329347admin.site.register(CustomArticle, CustomArticleAdmin)
    330348admin.site.register(Section, save_as=True, inlines=[ArticleInline])
     
    343361admin.site.register(Fabric, FabricAdmin)
    344362admin.site.register(Gallery, GalleryAdmin)
    345363admin.site.register(Picture, PictureAdmin)
     364admin.site.register(Recommendation, RecommendationAdmin)
     365admin.site.register(Recommender)
    346366
    347367# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
    348368# 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}}]
Back to Top