diff --git a/django/forms/models.py b/django/forms/models.py
index 86eecee..910253c 100644
a
|
b
|
class BaseModelFormSet(BaseFormSet):
|
560 | 560 | # data back. Generally, pk.editable should be false, but for some |
561 | 561 | # reason, auto_created pk fields and AutoField's editable attribute is |
562 | 562 | # True, so check for that as well. |
563 | | def pk_is_editable(pk): |
| 563 | def pk_is_not_editable(pk): |
564 | 564 | 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: |
567 | 567 | try: |
568 | 568 | pk_value = self.get_queryset()[index].pk |
569 | 569 | except IndexError: |
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):
|
325 | 325 | class PictureAdmin(admin.ModelAdmin): |
326 | 326 | pass |
327 | 327 | |
| 328 | |
| 329 | class 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 | |
| 338 | class LanguageAdmin(admin.ModelAdmin): |
| 339 | list_display = ['iso', 'shortlist', 'english_name', 'name'] |
| 340 | list_editable = ['shortlist'] |
| 341 | |
328 | 342 | admin.site.register(Article, ArticleAdmin) |
329 | 343 | admin.site.register(CustomArticle, CustomArticleAdmin) |
330 | 344 | admin.site.register(Section, save_as=True, inlines=[ArticleInline]) |
… |
… |
admin.site.register(EmptyModel, EmptyModelAdmin)
|
343 | 357 | admin.site.register(Fabric, FabricAdmin) |
344 | 358 | admin.site.register(Gallery, GalleryAdmin) |
345 | 359 | admin.site.register(Picture, PictureAdmin) |
| 360 | admin.site.register(Language, LanguageAdmin) |
346 | 361 | |
347 | 362 | # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2. |
348 | 363 | # That way we cover all four cases: |
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
|
16 | 16 | from models import (Article, BarAccount, CustomArticle, EmptyModel, |
17 | 17 | ExternalSubscriber, FooAccount, Gallery, |
18 | 18 | ModelWithStringPrimaryKey, Person, Persona, Picture, |
19 | | Podcast, Section, Subscriber, Vodcast) |
| 19 | Podcast, Section, Subscriber, Vodcast, Language) |
20 | 20 | |
21 | 21 | try: |
22 | 22 | set |
… |
… |
class AdminViewListEditable(TestCase):
|
824 | 824 | response = self.client.get('/test_admin/admin/admin_views/vodcast/') |
825 | 825 | self.failUnlessEqual(response.status_code, 200) |
826 | 826 | |
| 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 | |
827 | 832 | def test_changelist_input_html(self): |
828 | 833 | response = self.client.get('/test_admin/admin/admin_views/person/') |
829 | 834 | # 2 inputs per object(the field and the hidden id field) = 6 |
… |
… |
class AdminInlineFileUploadTest(TestCase):
|
1132 | 1137 | } |
1133 | 1138 | response = self.client.post('/test_admin/%s/admin_views/gallery/1/' % self.urlbit, post_data) |
1134 | 1139 | self.failUnless(response._container[0].find("Currently:") > -1) |
1135 | | |