<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _write_related_m2m_relations(self, obj, many_to_many_relationships):
 """ For the given `many_to_many_relationships` dict mapping field names to a list of object instances, apply the instance listing to the `obj`s named many-to-many relationship field. """

        for fieldname, related_objs in many_to_many_relationships.items():
            # TODO On PATCH avoid clearing existing relationships not provided?
            setattr(obj, fieldname, related_objs)