1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Remove Admin's swallowing of AttributeError (#16655, #18593, #18747)

During the new-admin changes, catching of AttributeError was added to
the admin.  This patch removes that as it's no longer possible to add a
value to a ModelAdmin that is not available.  Adding an attribute that
can not be called causes an ImproperlyConfigured exception to be raised.
This commit is contained in:
Travis Swicegood
2012-09-08 11:18:08 -04:00
parent e69348b4e7
commit ccd1bb0d81
5 changed files with 37 additions and 4 deletions

View File

@@ -27,11 +27,14 @@ from .models import (Article, Chapter, Account, Media, Child, Parent, Picture,
Album, Question, Answer, ComplexSortedPerson, PrePopulatedPostLargeSlug,
AdminOrderedField, AdminOrderedModelMethod, AdminOrderedAdminMethod,
AdminOrderedCallable, Report, Color2, UnorderedObject, MainPrepopulated,
RelatedPrepopulated, UndeletableObject)
RelatedPrepopulated, UndeletableObject, Simple)
def callable_year(dt_value):
return dt_value.year
try:
return dt_value.year
except AttributeError:
return None
callable_year.admin_order_field = 'date'
@@ -575,6 +578,14 @@ class UndeletableObjectAdmin(admin.ModelAdmin):
return super(UndeletableObjectAdmin, self).change_view(*args, **kwargs)
def callable_on_unknown(obj):
return obj.unknown
class AttributeErrorRaisingAdmin(admin.ModelAdmin):
list_display = [callable_on_unknown, ]
site = admin.AdminSite(name="admin")
site.register(Article, ArticleAdmin)
site.register(CustomArticle, CustomArticleAdmin)
@@ -648,6 +659,7 @@ site.register(AdminOrderedModelMethod, AdminOrderedModelMethodAdmin)
site.register(AdminOrderedAdminMethod, AdminOrderedAdminMethodAdmin)
site.register(AdminOrderedCallable, AdminOrderedCallableAdmin)
site.register(Color2, CustomTemplateFilterColorAdmin)
site.register(Simple, AttributeErrorRaisingAdmin)
# Register core models we need in our tests
from django.contrib.auth.models import User, Group