From 4a88785e38db53187e585cdfab78abc8166a8a8a Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Wed, 18 Mar 2009 03:03:24 +0000 Subject: [PATCH] Fixed #10530, #10527: added a couple more validation errors around `list_editable`. Thanks, Florian Apolloner. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10080 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/validation.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py index fa6d7e3e60..92485cac7b 100644 --- a/django/contrib/admin/validation.py +++ b/django/contrib/admin/validation.py @@ -71,21 +71,30 @@ def validate(cls, model): raise ImproperlyConfigured("'%s.list_editable' cannot be used " "without a default ordering. Please define ordering on either %s or %s." % (cls.__name__, cls.__name__, model.__name__)) - for idx, field in enumerate(cls.list_editable): + for idx, field_name in enumerate(cls.list_editable): try: - opts.get_field_by_name(field) + field = opts.get_field_by_name(field_name)[0] except models.FieldDoesNotExist: raise ImproperlyConfigured("'%s.list_editable[%d]' refers to a " - "field, '%s', not defiend on %s." % (cls.__name__, idx, field, model.__name__)) - if field not in cls.list_display: + "field, '%s', not defiend on %s." + % (cls.__name__, idx, field_name, model.__name__)) + if field_name not in cls.list_display: raise ImproperlyConfigured("'%s.list_editable[%d]' refers to " "'%s' which is not defined in 'list_display'." - % (cls.__name__, idx, field)) - if field in cls.list_display_links: + % (cls.__name__, idx, field_name)) + if field_name in cls.list_display_links: raise ImproperlyConfigured("'%s' cannot be in both '%s.list_editable'" " and '%s.list_display_links'" - % (field, cls.__name__, cls.__name__)) - + % (field_name, cls.__name__, cls.__name__)) + if not cls.list_display_links and cls.list_display[0] in cls.list_editable: + raise ImproperlyConfigured("'%s.list_editable[%d]' refers to" + " the first field in list_display, '%s', which can't be" + " used unless list_display_links is set." + % (cls.__name__, idx, cls.list_display[0])) + if not field.editable: + raise ImproperlyConfigured("'%s.list_editable[%d]' refers to a " + "field, '%s', which isn't editable through the admin." + % (cls.__name__, idx, field_name)) # search_fields = () if hasattr(cls, 'search_fields'):