Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #13004: Ensure the add page for a model with a ManyToManyField …

…specified

in readonly_fields does not raise an exception. Thanks hejsan, mlavin, copelco.



git-svn-id: http://code.djangoproject.com/svn/django/trunk@12827 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f88c2f16e84703cff225e162297a6bcedebe8910 1 parent 8661cb9
Karen Tracey authored March 21, 2010
2  django/contrib/admin/helpers.py
@@ -154,7 +154,7 @@ def contents(self):
154 154
         field, obj, model_admin = self.field, self.form.instance, self.model_admin
155 155
         try:
156 156
             f, attr, value = lookup_field(field, obj, model_admin)
157  
-        except (AttributeError, ObjectDoesNotExist):
  157
+        except (AttributeError, ValueError, ObjectDoesNotExist):
158 158
             result_repr = EMPTY_CHANGELIST_VALUE
159 159
         else:
160 160
             if f is None:
12  tests/regressiontests/admin_views/models.py
@@ -565,6 +565,16 @@ class CyclicTwo(models.Model):
565 565
     def __unicode__(self):
566 566
         return self.name
567 567
 
  568
+class Topping(models.Model):
  569
+    name = models.CharField(max_length=20) 
  570
+
  571
+class Pizza(models.Model):
  572
+    name = models.CharField(max_length=20)
  573
+    toppings = models.ManyToManyField('Topping')
  574
+
  575
+class PizzaAdmin(admin.ModelAdmin):
  576
+    readonly_fields = ('toppings',)
  577
+
568 578
 admin.site.register(Article, ArticleAdmin)
569 579
 admin.site.register(CustomArticle, CustomArticleAdmin)
570 580
 admin.site.register(Section, save_as=True, inlines=[ArticleInline])
@@ -609,3 +619,5 @@ def __unicode__(self):
609 619
 admin.site.register(Book, inlines=[ChapterInline])
610 620
 admin.site.register(Promo)
611 621
 admin.site.register(ChapterXtra1)
  622
+admin.site.register(Pizza, PizzaAdmin)
  623
+admin.site.register(Topping)
5  tests/regressiontests/admin_views/tests.py
@@ -1986,6 +1986,11 @@ def test_readonly_post(self):
1986 1986
         p = Post.objects.order_by('-id')[0]
1987 1987
         self.assertEqual(p.posted, datetime.date.today())
1988 1988
 
  1989
+    def test_readonly_manytomany(self):
  1990
+        "Regression test for #13004"
  1991
+        response = self.client.get('/test_admin/admin/admin_views/pizza/add/')
  1992
+        self.assertEqual(response.status_code, 200)
  1993
+
1989 1994
 class IncompleteFormTest(TestCase):
1990 1995
     """
1991 1996
     Tests validation of a ModelForm that doesn't explicitly have all data

0 notes on commit f88c2f1

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