Ticket #13004: catch_error_with_test-12818.diff

File catch_error_with_test-12818.diff, 2.2 KB (added by Mark Lavin, 15 years ago)

Added a basic regression test along with the orginal patch.

  • django/contrib/admin/helpers.py

     
    154154        field, obj, model_admin = self.field, self.form.instance, self.model_admin
    155155        try:
    156156            f, attr, value = lookup_field(field, obj, model_admin)
    157         except (AttributeError, ObjectDoesNotExist):
     157        except (AttributeError, ValueError, ObjectDoesNotExist):
    158158            result_repr = EMPTY_CHANGELIST_VALUE
    159159        else:
    160160            if f is None:
  • tests/regressiontests/admin_views/tests.py

     
    19861986        p = Post.objects.order_by('-id')[0]
    19871987        self.assertEqual(p.posted, datetime.date.today())
    19881988
     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
    19891994class IncompleteFormTest(TestCase):
    19901995    """
    19911996    Tests validation of a ModelForm that doesn't explicitly have all data
  • tests/regressiontests/admin_views/models.py

     
    565565    def __unicode__(self):
    566566        return self.name
    567567
     568class Topping(models.Model):
     569    name = models.CharField(max_length=20)
     570
     571class Pizza(models.Model):
     572    name = models.CharField(max_length=20)
     573    toppings = models.ManyToManyField('Topping')
     574
     575class PizzaAdmin(admin.ModelAdmin):
     576    readonly_fields = ('toppings',)
     577
    568578admin.site.register(Article, ArticleAdmin)
    569579admin.site.register(CustomArticle, CustomArticleAdmin)
    570580admin.site.register(Section, save_as=True, inlines=[ArticleInline])
     
    609619admin.site.register(Book, inlines=[ChapterInline])
    610620admin.site.register(Promo)
    611621admin.site.register(ChapterXtra1)
     622admin.site.register(Pizza, PizzaAdmin)
     623admin.site.register(Topping)
Back to Top