'When saving an object with a M2M field, don\'t save that related object\'s related objects.'

def test_no_save_m2m_related(self):

    cg1 = ContactGroup.objects.create(name='The    Inebriati')
    cg2 = ContactGroup.objects.create(name='The    Stone    Cutters')
    c1 = Contact.objects.create(name='foo')
    c2 = Contact.objects.create(name='bar')
    c2.groups.add(cg1, cg2)
    c3 = Contact.objects.create(name='baz')
    c3.groups.add(cg1)
    self.assertEqual(list(c1.groups.all()), [])
    self.assertEqual(list(c2.groups.all()), [cg1, cg2])
    self.assertEqual(list(c3.groups.all()), [cg1])
    data = {'name': c1.name, 'groups': [reverse('api_dispatch_detail', kwargs={'api_name': 'v1', 'resource_name': 'contactgroup', 'pk': cg1.pk})]}
    resource = api.canonical_resource_for('contact')
    request = MockRequest()
    request.GET = {'format': 'json'}
    request.method = 'PUT'
    request._load_post_and_files = (lambda *args, **kwargs: None)
    request.set_body(json.dumps(data))
    with self.assertNumQueries(8):
        response = resource.wrap_view('dispatch_detail')(request, pk=c1.pk)
    self.assertEqual(response.status_code, 204, response.content)
    new_contacts = Contact.objects.all()
    new_c1 = new_contacts[0]
    new_c2 = new_contacts[1]
    new_c3 = new_contacts[2]
    self.assertEqual(new_c1.name, c1.name)
    self.assertEqual(new_c1.id, c1.id)
    self.assertEqual(list(new_c1.groups.all()), [cg1])
    self.assertEqual(new_c2.id, c2.id)
    self.assertEqual(list(new_c2.groups.all()), [cg1, cg2])
    self.assertEqual(new_c3.id, c3.id)
    self.assertEqual(list(new_c3.groups.all()), [cg1])
    new_cg1 = ContactGroup.objects.get(id=cg1.id)
    new_cg2 = ContactGroup.objects.get(id=cg2.id)
    self.assertEqual(list(new_cg1.members.all()), [new_c1, new_c2, new_c3])
    self.assertEqual(list(new_cg2.members.all()), [new_c2])
