<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _build_dictionary(self, models):
 """ Build a dictionary with the models. :param models: The models :type models: Collection """

        for model in models:
            key = getattr(model, self._morph_type, None)
            if key:
                foreign = getattr(model, self._foreign_key)
                if key not in self._dictionary:
                    self._dictionary[key] = {}

                if foreign not in self._dictionary[key]:
                    self._dictionary[key][foreign] = []

                self._dictionary[key][foreign].append(model)