Ticket #10893: list-editable.diff

File list-editable.diff, 5.2 KB (added by Alex Gaynor, 16 years ago)
  • django/forms/models.py

    diff --git a/django/forms/models.py b/django/forms/models.py
    index 626e727..d43595f 100644
    a b class BaseModelFormSet(BaseFormSet):  
    488488        # data back. Generally, pk.editable should be false, but for some
    489489        # reason, auto_created pk fields and AutoField's editable attribute is
    490490        # True, so check for that as well.
    491         def pk_is_editable(pk):
     491        def pk_is_not_editable(pk):
    492492            return ((not pk.editable) or (pk.auto_created or isinstance(pk, AutoField))
    493                 or (pk.rel and pk.rel.parent_link and pk_is_editable(pk.rel.to._meta.pk)))
    494         if pk_is_editable(pk):
     493                or (pk.rel and pk.rel.parent_link and pk_is_not_editable(pk.rel.to._meta.pk)))
     494        if pk_is_not_editable(pk) or pk.name not in form.fields:
    495495            try:
    496496                pk_value = self.get_queryset()[index].pk
    497497            except IndexError:
  • tests/regressiontests/admin_views/models.py

    diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
    index 84a1688..dbadee4 100644
    a b class GalleryAdmin(admin.ModelAdmin):  
    325325class PictureAdmin(admin.ModelAdmin):
    326326    pass
    327327
     328
     329class Language(models.Model):
     330    iso = models.CharField(max_length=5, primary_key=True)
     331    name = models.CharField(max_length=50)
     332    english_name = models.CharField(max_length=50)
     333    shortlist = models.BooleanField(default=False)
     334
     335    class Meta:
     336        ordering = ('iso',)
     337
     338class LanguageAdmin(admin.ModelAdmin):
     339    list_display = ['iso', 'shortlist', 'english_name', 'name']
     340    list_editable = ['shortlist']
     341
    328342admin.site.register(Article, ArticleAdmin)
    329343admin.site.register(CustomArticle, CustomArticleAdmin)
    330344admin.site.register(Section, save_as=True, inlines=[ArticleInline])
    admin.site.register(EmptyModel, EmptyModelAdmin)  
    343357admin.site.register(Fabric, FabricAdmin)
    344358admin.site.register(Gallery, GalleryAdmin)
    345359admin.site.register(Picture, PictureAdmin)
     360admin.site.register(Language, LanguageAdmin)
    346361
    347362# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
    348363# That way we cover all four cases:
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index 3d75967..4dab266 100644
    a b from django.utils.html import escape  
    1616from models import (Article, BarAccount, CustomArticle, EmptyModel,
    1717                    ExternalSubscriber, FooAccount, Gallery,
    1818                    ModelWithStringPrimaryKey, Person, Persona, Picture,
    19                     Podcast, Section, Subscriber, Vodcast)
     19                    Podcast, Section, Subscriber, Vodcast, Language)
    2020
    2121try:
    2222    set
    class AdminViewListEditable(TestCase):  
    804804        response = self.client.get('/test_admin/admin/admin_views/vodcast/')
    805805        self.failUnlessEqual(response.status_code, 200)
    806806
     807    def test_custom_pk(self):
     808        Language.objects.create(iso='en', name='English', english_name='English')
     809        response = self.client.get('/test_admin/admin/admin_views/language/')
     810        self.failUnlessEqual(response.status_code, 200)
     811
    807812    def test_changelist_input_html(self):
    808813        response = self.client.get('/test_admin/admin/admin_views/person/')
    809814        # 2 inputs per object(the field and the hidden id field) = 6
    class AdminActionsTest(TestCase):  
    10031008        }
    10041009        response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data)
    10051010        self.failUnlessEqual(response.status_code, 302)
    1006        
     1011
    10071012    def test_model_without_action(self):
    10081013        "Tests a ModelAdmin without any action"
    10091014        response = self.client.get('/test_admin/admin/admin_views/oldsubscriber/')
    class AdminActionsTest(TestCase):  
    10121017            '<input type="checkbox" class="action-select"' not in response.content,
    10131018            "Found an unexpected action toggle checkboxbox in response"
    10141019        )
    1015        
     1020
    10161021    def test_multiple_actions_form(self):
    10171022        """
    10181023        Test that actions come from the form whose submit button was pressed (#10618).
    class AdminInlineFileUploadTest(TestCase):  
    10761081
    10771082    def setUp(self):
    10781083        self.client.login(username='super', password='secret')
    1079        
     1084
    10801085        # Set up test Picture and Gallery.
    10811086        # These must be set up here instead of in fixtures in order to allow Picture
    10821087        # to use a NamedTemporaryFile.
    class AdminInlineFileUploadTest(TestCase):  
    10951100
    10961101    def test_inline_file_upload_edit_validation_error_post(self):
    10971102        """
    1098         Test that inline file uploads correctly display prior data (#10002). 
     1103        Test that inline file uploads correctly display prior data (#10002).
    10991104        """
    11001105        post_data = {
    11011106            "name": u"Test Gallery",
    class AdminInlineFileUploadTest(TestCase):  
    11121117        }
    11131118        response = self.client.post('/test_admin/%s/admin_views/gallery/1/' % self.urlbit, post_data)
    11141119        self.failUnless(response._container[0].find("Currently:") > -1)
    1115 
Back to Top