Code

Ticket #10784: 10784-admin-list_editable-ordering-validation.diff

File 10784-admin-list_editable-ordering-validation.diff, 872 bytes (added by Will Hardy, 5 years ago)

Alternative to fixing problem: Admin validation to prevent the situation arising.

Line 
1Index: django/contrib/admin/validation.py
2===================================================================
3--- django/contrib/admin/validation.py  (revision 10838)
4+++ django/contrib/admin/validation.py  (working copy)
5@@ -91,6 +91,11 @@
6                 raise ImproperlyConfigured("'%s.list_editable[%d]' refers to a "
7                     "field, '%s', which isn't editable through the admin."
8                     % (cls.__name__, idx, field_name))
9+            if not field.unique and (field_name in (cls.ordering or opts.ordering or ())):
10+                raise ImproperlyConfigured("'%s.list_editable[%d]' refers to a "
11+                    "non-unique field, '%s', which controls the ordering of "
12+                    "items in the admin."
13+                    % (cls.__name__, idx, field_name))
14 
15     # search_fields = ()
16     if hasattr(cls, 'search_fields'):