Code

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

File 10784-admin-list_editable-ordering.diff, 2.7 KB (added by django, 5 years ago)

Regression test for a problem with list_editable on fields that order.

Line 
1Index: tests/regressiontests/admin_views/tests.py
2===================================================================
3--- tests/regressiontests/admin_views/tests.py  (revision 10838)
4+++ tests/regressiontests/admin_views/tests.py  (working copy)
5@@ -16,7 +16,7 @@
6 from models import Article, BarAccount, CustomArticle, EmptyModel, \
7     ExternalSubscriber, FooAccount, Gallery, ModelWithStringPrimaryKey, \
8     Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, \
9-    Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit
10+    Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, Category
11 
12 try:
13     set
14@@ -921,6 +921,38 @@
15 
16         self.failUnlessEqual(Person.objects.get(name="John Mauchly").alive, False)
17 
18+    def test_list_editable_ordering(self):
19+
20+        Category.objects.create(id=1, order=1)
21+        Category.objects.create(id=2, order=2)
22+        Category.objects.create(id=3, order=0)
23+        Category.objects.create(id=4, order=0)
24+
25+        # NB: The order values must be changed so that the items are reordered.
26+        data = {
27+            "form-TOTAL_FORMS": "4",
28+            "form-INITIAL_FORMS": "4",
29+
30+            "form-0-order": "14",
31+            "form-0-id": "1",
32+
33+            "form-1-order": "13",
34+            "form-1-id": "2",
35+
36+            "form-2-order": "1",
37+            "form-2-id": "3",
38+
39+            "form-3-order": "0",
40+            "form-3-id": "4",
41+        }
42+        self.client.post('/test_admin/admin/admin_views/category/', data)
43+
44+        self.failUnlessEqual(Category.objects.get(id=1).order, 14)
45+        self.failUnlessEqual(Category.objects.get(id=2).order, 13)
46+        self.failUnlessEqual(Category.objects.get(id=3).order, 1)
47+        self.failUnlessEqual(Category.objects.get(id=4).order, 0)
48+
49+
50 class AdminSearchTest(TestCase):
51     fixtures = ['admin-views-users','multiple-child-classes']
52 
53Index: tests/regressiontests/admin_views/models.py
54===================================================================
55--- tests/regressiontests/admin_views/models.py (revision 10838)
56+++ tests/regressiontests/admin_views/models.py (working copy)
57@@ -326,7 +326,16 @@
58 class PictureAdmin(admin.ModelAdmin):
59     pass
60 
61+class Category(models.Model):
62+    order = models.PositiveIntegerField()
63 
64+    class Meta:
65+        ordering = ('order',)
66+
67+class CategoryAdmin(admin.ModelAdmin):
68+    list_display = ('id', 'order')
69+    list_editable = ('order',)
70+
71 class Language(models.Model):
72     iso = models.CharField(max_length=5, primary_key=True)
73     name = models.CharField(max_length=50)
74@@ -439,3 +448,4 @@
75 admin.site.register(Book, inlines=[ChapterInline])
76 admin.site.register(Promo)
77 admin.site.register(ChapterXtra1)
78+admin.site.register(Category, CategoryAdmin)