Ticket #10893: list_editable.2.diff

File list_editable.2.diff, 3.7 KB (added by Antti Kaihola, 16 years ago)

fixed whitespace strangeness in tests.py diff, updated for trunk@10675

  • django/forms/models.py

    diff --git a/django/forms/models.py b/django/forms/models.py
    index 86eecee..910253c 100644
    a b class BaseModelFormSet(BaseFormSet):  
    560560        # data back. Generally, pk.editable should be false, but for some
    561561        # reason, auto_created pk fields and AutoField's editable attribute is
    562562        # True, so check for that as well.
    563         def pk_is_editable(pk):
     563        def pk_is_not_editable(pk):
    564564            return ((not pk.editable) or (pk.auto_created or isinstance(pk, AutoField))
    565                 or (pk.rel and pk.rel.parent_link and pk_is_editable(pk.rel.to._meta.pk)))
    566         if pk_is_editable(pk):
     565                or (pk.rel and pk.rel.parent_link and pk_is_not_editable(pk.rel.to._meta.pk)))
     566        if pk_is_not_editable(pk) or pk.name not in form.fields:
    567567            try:
    568568                pk_value = self.get_queryset()[index].pk
    569569            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 960923b..a435003 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):  
    824824        response = self.client.get('/test_admin/admin/admin_views/vodcast/')
    825825        self.failUnlessEqual(response.status_code, 200)
    826826
     827    def test_custom_pk(self):
     828        Language.objects.create(iso='en', name='English', english_name='English')
     829        response = self.client.get('/test_admin/admin/admin_views/language/')
     830        self.failUnlessEqual(response.status_code, 200)
     831
    827832    def test_changelist_input_html(self):
    828833        response = self.client.get('/test_admin/admin/admin_views/person/')
    829834        # 2 inputs per object(the field and the hidden id field) = 6
    class AdminInlineFileUploadTest(TestCase):  
    11321137        }
    11331138        response = self.client.post('/test_admin/%s/admin_views/gallery/1/' % self.urlbit, post_data)
    11341139        self.failUnless(response._container[0].find("Currently:") > -1)
    1135 
Back to Top