

def get_held_by_pokemon(self, obj):
    pokemon_items = PokemonItem.objects.filter(item=obj).order_by('pokemon_id')
    pokemon_ids = pokemon_items.values('pokemon_id').distinct()
    pokemon_list = []
    for id in pokemon_ids:
        item_pokemon_details = OrderedDict()
        pokemon_object = Pokemon.objects.get(pk=id['pokemon_id'])
        pokemon_data = PokemonSummarySerializer(pokemon_object, context=self.context).data
        item_pokemon_details['pokemon'] = pokemon_data
        pokemon_item_objects = pokemon_items.filter(pokemon_id=id['pokemon_id'])
        serializer = PokemonItemSerializer(pokemon_item_objects, many=True, context=self.context)
        item_pokemon_details['version_details'] = []
        for pokemon in serializer.data:
            version_detail = OrderedDict()
            version_detail['rarity'] = pokemon['rarity']
            version_detail['version'] = pokemon['version']
            item_pokemon_details['version_details'].append(version_detail)
        pokemon_list.append(item_pokemon_details)
    return pokemon_list

dataset/ETHPy150Open phalt/pokeapi/pokemon_v2/serializers.py ItemDetailSerializer.get_held_by_pokemon/original