def test_lookup_by_tag(self):
    apple = self.food_model.objects.create(name='apple')
    apple.tags.add('red', 'green')
    pear = self.food_model.objects.create(name='pear')
    pear.tags.add('green')
    self.assertEqual(list(self.food_model.objects.filter(tags__name__in=['red'])), [apple])
    self.assertEqual(list(self.food_model.objects.filter(tags__name__in=['green'])), [apple, pear])
    kitty = self.pet_model.objects.create(name='kitty')
    kitty.tags.add('fuzzy', 'red')
    dog = self.pet_model.objects.create(name='dog')
    dog.tags.add('woof', 'red')
    self.assertEqual(list(self.food_model.objects.filter(tags__name__in=['red']).distinct()), [apple])
    tag = self.tag_model.objects.get(name='woof')
    self.assertEqual(list(self.pet_model.objects.filter(tags__in=[tag])), [dog])
    cat = self.housepet_model.objects.create(name='cat', trained=True)
    cat.tags.add('fuzzy')
    pks = self.pet_model.objects.filter(tags__name__in=['fuzzy'])
    model_name = self.pet_model.__name__
    self.assertQuerysetEqual(pks, ['<{0}: kitty>'.format(model_name), '<{0}: cat>'.format(model_name)], ordered=False)
def test_lookup_by_tag(self):
    apple = self.food_model.objects.create(name='apple')
    apple.tags.add('red', 'green')
    pear = self.food_model.objects.create(name='pear')
    pear.tags.add('green')
    self.assertEqual(list(self.food_model.objects.filter(tags__name__in=['red'])), [apple])
    self.assertEqual(list(self.food_model.objects.filter(tags__name__in=['green'])), [apple, pear])
    kitty = self.pet_model.objects.create(name='kitty')
    kitty.tags.add('fuzzy', 'red')
    dog = self.pet_model.objects.create(name='dog')
    dog.tags.add('woof', 'red')
    self.assertEqual(list(self.food_model.objects.filter(tags__name__in=['red']).distinct()), [apple])
    tag = self.tag_model.objects.get(name='woof')
    self.assertEqual(list(self.pet_model.objects.filter(tags__in=[tag])), [dog])
    cat = self.housepet_model.objects.create(name='cat', trained=True)
    cat.tags.add('fuzzy')
    pks = self.pet_model.objects.filter(tags__name__in=['fuzzy'])
    model_name = self.pet_model.__name__
    self.assertQuerysetEqual(pks, ['<{0}: kitty>'.format(model_name), '<{0}: cat>'.format(model_name)], ordered=False)