'Regression test for #10870:  Aggregates with joins ignore extra
filters provided by setup_joins
tests aggregations with generic reverse relations'

def test_aggregation_with_generic_reverse_relation(self):

    b = Book.objects.get(name=u'Practical    Django    Projects')
    ItemTag.objects.create(object_id=b.id, tag=u'intermediate', content_type=ContentType.objects.get_for_model(b))
    ItemTag.objects.create(object_id=b.id, tag=u'django', content_type=ContentType.objects.get_for_model(b))
    wmpk = WithManualPK.objects.create(id=b.pk)
    ItemTag.objects.create(object_id=wmpk.id, tag=u'hi    mom', content_type=ContentType.objects.get_for_model(wmpk))
    b = Book.objects.get(name__startswith=u'Paradigms    of    Artificial    Intelligence')
    ItemTag.objects.create(object_id=b.id, tag=u'intermediate', content_type=ContentType.objects.get_for_model(b))
    self.assertEqual(Book.objects.aggregate(Count(u'tags')), {u'tags__count': 3})
    results = Book.objects.annotate(Count(u'tags')).order_by(u'-tags__count', u'name')
    self.assertEqual([(b.name, b.tags__count) for b in results], [(u'Practical    Django    Projects', 2), (u'Paradigms    of    Artificial    Intelligence    Programming:    Case    Studies    in    Common    Lisp', 1), (u'Artificial    Intelligence:    A    Modern    Approach', 0), (u'Python    Web    Development    with    Django', 0), (u'Sams    Teach    Yourself    Django    in    24    Hours', 0), (u'The    Definitive    Guide    to    Django:    Web    Development    Done    Right', 0)])
