def test_similarity_by_tag(self):
    'Test that pears are more similar to apples than watermelons'
    apple = self.food_model.objects.create(name='apple')
    apple.tags.add('green', 'juicy', 'small', 'sour')
    pear = self.food_model.objects.create(name='pear')
    pear.tags.add('green', 'juicy', 'small', 'sweet')
    watermelon = self.food_model.objects.create(name='watermelon')
    watermelon.tags.add('green', 'juicy', 'large', 'sweet')
    similar_objs = apple.tags.similar_objects()
    self.assertEqual(similar_objs, [pear, watermelon])
    self.assertEqual([obj.similar_tags for obj in similar_objs], [3, 2])
Test that pears are more similar to apples than watermelons
def test_similarity_by_tag(self):
    
    apple = self.food_model.objects.create(name='apple')
    apple.tags.add('green', 'juicy', 'small', 'sour')
    pear = self.food_model.objects.create(name='pear')
    pear.tags.add('green', 'juicy', 'small', 'sweet')
    watermelon = self.food_model.objects.create(name='watermelon')
    watermelon.tags.add('green', 'juicy', 'large', 'sweet')
    similar_objs = apple.tags.similar_objects()
    self.assertEqual(similar_objs, [pear, watermelon])
    self.assertEqual([obj.similar_tags for obj in similar_objs], [3, 2])