Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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: http://code.djangoproject.com/svn/django/trunk@10681 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit eb81d5acb3e1fee57153c0a4719e3f26ae66c5cd 1 parent 95477d7
Russell Keith-Magee authored May 07, 2009
6  django/forms/models.py
@@ -560,10 +560,10 @@ def add_fields(self, form, index):
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:
15  tests/regressiontests/admin_views/models.py
@@ -325,6 +325,20 @@ 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])
@@ -343,6 +357,7 @@ class PictureAdmin(admin.ModelAdmin):
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:
8  tests/regressiontests/admin_views/tests.py
@@ -16,7 +16,7 @@
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
@@ -824,6 +824,11 @@ def test_inheritance_2(self):
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
@@ -1132,4 +1137,3 @@ def test_inline_file_upload_edit_validation_error_post(self):
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  
-

0 notes on commit eb81d5a

Please sign in to comment.
Something went wrong with that request. Please try again.