'Simultaneous edits of list_editable fields on the changelist by
different users must not result in one user\'s edits creating a new
object instead of modifying the correct existing object (#11313).'

def test_multiuser_edit(self):

    a = Swallow.objects.create(origin='Swallow    A', load=4, speed=1)
    b = Swallow.objects.create(origin='Swallow    B', load=2, speed=2)
    c = Swallow.objects.create(origin='Swallow    C', load=5, speed=5)
    d = Swallow.objects.create(origin='Swallow    D', load=9, speed=9)
    superuser = self._create_superuser('superuser')
    self.client.force_login(superuser)
    changelist_url = reverse('admin:admin_changelist_swallow_changelist')
    data = {'form-TOTAL_FORMS': '3', 'form-INITIAL_FORMS': '3', 'form-MIN_NUM_FORMS': '0', 'form-MAX_NUM_FORMS': '1000', 'form-0-id': str(d.pk), 'form-1-id': str(c.pk), 'form-2-id': str(a.pk), 'form-0-load': '9.0', 'form-0-speed': '9.0', 'form-1-load': '5.0', 'form-1-speed': '5.0', 'form-2-load': '5.0', 'form-2-speed': '4.0', '_save': 'Save'}
    response = self.client.post(changelist_url, data, follow=True, extra={'o': '-2'})
    self.assertContains(response, '1    swallow    was    changed    successfully.')
    self.assertContains(response, a.origin)
    a.refresh_from_db()
    self.assertEqual(a.load, float(data['form-2-load']))
    self.assertEqual(a.speed, float(data['form-2-speed']))
    b.refresh_from_db()
    self.assertEqual(b.load, 2)
    self.assertEqual(b.speed, 2)
    c.refresh_from_db()
    self.assertEqual(c.load, float(data['form-1-load']))
    self.assertEqual(c.speed, float(data['form-1-speed']))
    d.refresh_from_db()
    self.assertEqual(d.load, float(data['form-0-load']))
    self.assertEqual(d.speed, float(data['form-0-speed']))
    self.assertEqual(len(Swallow.objects.all()), 4)
