Browse files

Fixed #10893 -- Corrected a problem with using list_editable in the a…

…dmin when the model has a manual primary key. Thanks to Alex Gaynor for the patch.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
freakboy3742 committed May 7, 2009
1 parent 95477d7 commit eb81d5acb3e1fee57153c0a4719e3f26ae66c5cd
@@ -560,10 +560,10 @@ def add_fields(self, form, index):
# data back. Generally, pk.editable should be false, but for some
# reason, auto_created pk fields and AutoField's editable attribute is
# True, so check for that as well.
def pk_is_editable(pk):
def pk_is_not_editable(pk):
return ((not pk.editable) or (pk.auto_created or isinstance(pk, AutoField))
or (pk.rel and pk.rel.parent_link and pk_is_editable(
if pk_is_editable(pk):
or (pk.rel and pk.rel.parent_link and pk_is_not_editable(
if pk_is_not_editable(pk) or not in form.fields:
pk_value = self.get_queryset()[index].pk
except IndexError:
@@ -325,6 +325,20 @@ class GalleryAdmin(admin.ModelAdmin):
class PictureAdmin(admin.ModelAdmin):
class Language(models.Model):
iso = models.CharField(max_length=5, primary_key=True)
name = models.CharField(max_length=50)
english_name = models.CharField(max_length=50)
shortlist = models.BooleanField(default=False)
class Meta:
ordering = ('iso',)
class LanguageAdmin(admin.ModelAdmin):
list_display = ['iso', 'shortlist', 'english_name', 'name']
list_editable = ['shortlist'], ArticleAdmin), CustomArticleAdmin), save_as=True, inlines=[ArticleInline])
@@ -343,6 +357,7 @@ class PictureAdmin(admin.ModelAdmin):, FabricAdmin), GalleryAdmin), PictureAdmin), LanguageAdmin)
# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
# That way we cover all four cases:
@@ -16,7 +16,7 @@
from models import (Article, BarAccount, CustomArticle, EmptyModel,
ExternalSubscriber, FooAccount, Gallery,
ModelWithStringPrimaryKey, Person, Persona, Picture,
Podcast, Section, Subscriber, Vodcast)
Podcast, Section, Subscriber, Vodcast, Language)
@@ -824,6 +824,11 @@ def test_inheritance_2(self):
response = self.client.get('/test_admin/admin/admin_views/vodcast/')
self.failUnlessEqual(response.status_code, 200)
def test_custom_pk(self):
Language.objects.create(iso='en', name='English', english_name='English')
response = self.client.get('/test_admin/admin/admin_views/language/')
self.failUnlessEqual(response.status_code, 200)
def test_changelist_input_html(self):
response = self.client.get('/test_admin/admin/admin_views/person/')
# 2 inputs per object(the field and the hidden id field) = 6
@@ -1132,4 +1137,3 @@ def test_inline_file_upload_edit_validation_error_post(self):
response ='/test_admin/%s/admin_views/gallery/1/' % self.urlbit, post_data)
self.failUnless(response._container[0].find("Currently:") > -1)

0 comments on commit eb81d5a

Please sign in to comment.