def test_lookup_bulk(self):
    apple = self.food_model.objects.create(name='apple')
    pear = self.food_model.objects.create(name='pear')
    apple.tags.add('fruit', 'green')
    pear.tags.add('fruit', 'yummie')

    def lookup_qs():
        objects = self.food_model.objects.all()
        lookup = self.taggeditem_model.bulk_lookup_kwargs(objects)
        list(self.taggeditem_model.objects.filter(**lookup))

    def lookup_list():
        objects = list(self.food_model.objects.all())
        lookup = self.taggeditem_model.bulk_lookup_kwargs(objects)
        list(self.taggeditem_model.objects.filter(**lookup))
    self.assertNumQueries(1, lookup_qs)
    self.assertNumQueries(2, lookup_list)
def test_lookup_bulk(self):
    apple = self.food_model.objects.create(name='apple')
    pear = self.food_model.objects.create(name='pear')
    apple.tags.add('fruit', 'green')
    pear.tags.add('fruit', 'yummie')

    def lookup_qs():
        objects = self.food_model.objects.all()
        lookup = self.taggeditem_model.bulk_lookup_kwargs(objects)
        list(self.taggeditem_model.objects.filter(**lookup))

    def lookup_list():
        objects = list(self.food_model.objects.all())
        lookup = self.taggeditem_model.bulk_lookup_kwargs(objects)
        list(self.taggeditem_model.objects.filter(**lookup))
    self.assertNumQueries(1, lookup_qs)
    self.assertNumQueries(2, lookup_list)