'For each instance of this model in base_objects, add a field named
related_list_name listing all the related objects of type related_model.
related_model must be in a many-to-one or many-to-many relationship with
this model.
:param base_objects - list of instances of this model
:param related_model - model class related to this model
:param related_list_name - attribute name in which to store the related
object list.'

def populate_relationships(self, base_objects, related_model, related_list_name):

    if (not base_objects):
        return
    base_objects_by_id = dict(((base_object._get_pk_val(), base_object) for base_object in base_objects))
    pivot_iterator = self._get_pivot_iterator(base_objects_by_id, related_model)
    for base_object in base_objects:
        setattr(base_object, related_list_name, [])
    for (base_object, related_object) in pivot_iterator:
        getattr(base_object, related_list_name).append(related_object)
