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

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

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

  • tests/regressiontests/admin_views/tests.py

     
    1616from models import Article, BarAccount, CustomArticle, EmptyModel, \
    1717    ExternalSubscriber, FooAccount, Gallery, ModelWithStringPrimaryKey, \
    1818    Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, \
    19     Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit
     19    Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, Category
    2020
    2121try:
    2222    set
     
    921921
    922922        self.failUnlessEqual(Person.objects.get(name="John Mauchly").alive, False)
    923923
     924    def test_list_editable_ordering(self):
     925
     926        Category.objects.create(id=1, order=1)
     927        Category.objects.create(id=2, order=2)
     928        Category.objects.create(id=3, order=0)
     929        Category.objects.create(id=4, order=0)
     930
     931        # NB: The order values must be changed so that the items are reordered.
     932        data = {
     933            "form-TOTAL_FORMS": "4",
     934            "form-INITIAL_FORMS": "4",
     935
     936            "form-0-order": "14",
     937            "form-0-id": "1",
     938
     939            "form-1-order": "13",
     940            "form-1-id": "2",
     941
     942            "form-2-order": "1",
     943            "form-2-id": "3",
     944
     945            "form-3-order": "0",
     946            "form-3-id": "4",
     947        }
     948        self.client.post('/test_admin/admin/admin_views/category/', data)
     949
     950        self.failUnlessEqual(Category.objects.get(id=1).order, 14)
     951        self.failUnlessEqual(Category.objects.get(id=2).order, 13)
     952        self.failUnlessEqual(Category.objects.get(id=3).order, 1)
     953        self.failUnlessEqual(Category.objects.get(id=4).order, 0)
     954
     955
    924956class AdminSearchTest(TestCase):
    925957    fixtures = ['admin-views-users','multiple-child-classes']
    926958
  • tests/regressiontests/admin_views/models.py

     
    326326class PictureAdmin(admin.ModelAdmin):
    327327    pass
    328328
     329class Category(models.Model):
     330    order = models.PositiveIntegerField()
    329331
     332    class Meta:
     333        ordering = ('order',)
     334
     335class CategoryAdmin(admin.ModelAdmin):
     336    list_display = ('id', 'order')
     337    list_editable = ('order',)
     338
    330339class Language(models.Model):
    331340    iso = models.CharField(max_length=5, primary_key=True)
    332341    name = models.CharField(max_length=50)
     
    439448admin.site.register(Book, inlines=[ChapterInline])
    440449admin.site.register(Promo)
    441450admin.site.register(ChapterXtra1)
     451admin.site.register(Category, CategoryAdmin)
Back to Top