'The primary key is used in the ordering of the changelist\'s results to
guarantee a deterministic order, even when the model has a manager that
defines a default ordering (#17198).'

def test_deterministic_order_for_model_ordered_by_its_manager(self):

    superuser = self._create_superuser('superuser')
    for counter in range(1, 51):
        OrderedObject.objects.create(id=counter, bool=True, number=counter)
    class OrderedObjectAdmin(admin.ModelAdmin, ):
        list_per_page = 10
    def check_results_order(ascending=False):
        custom_site.register(OrderedObject, OrderedObjectAdmin)
        model_admin = OrderedObjectAdmin(OrderedObject, custom_site)
        counter = (0 if ascending else 51)
        for page in range(0, 5):
            request = self._mocked_authenticated_request(('/orderedobject/?p=%s' % page), superuser)
            response = model_admin.changelist_view(request)
            for result in response.context_data['cl'].result_list:
                counter += (1 if ascending else (-1))
                self.assertEqual(result.id, counter)
        custom_site.unregister(OrderedObject)
    check_results_order(ascending=True)
    OrderedObjectAdmin.ordering = ['bool']
    check_results_order()
    OrderedObjectAdmin.ordering = ['bool', '-pk']
    check_results_order()
    OrderedObjectAdmin.ordering = ['bool', 'pk']
    check_results_order(ascending=True)
    OrderedObjectAdmin.ordering = ['-id', 'bool']
    check_results_order()
    OrderedObjectAdmin.ordering = ['id', 'bool']
    check_results_order(ascending=True)
