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
This commit is contained in:
Jacob Kaplan-Moss 2009-03-18 03:03:24 +00:00
parent 324eba99cb
commit 4a88785e38
1 changed files with 17 additions and 8 deletions

View File

@ -71,21 +71,30 @@ def validate(cls, model):
raise ImproperlyConfigured("'%s.list_editable' cannot be used " raise ImproperlyConfigured("'%s.list_editable' cannot be used "
"without a default ordering. Please define ordering on either %s or %s." "without a default ordering. Please define ordering on either %s or %s."
% (cls.__name__, cls.__name__, model.__name__)) % (cls.__name__, cls.__name__, model.__name__))
for idx, field in enumerate(cls.list_editable): for idx, field_name in enumerate(cls.list_editable):
try: try:
opts.get_field_by_name(field) field = opts.get_field_by_name(field_name)[0]
except models.FieldDoesNotExist: except models.FieldDoesNotExist:
raise ImproperlyConfigured("'%s.list_editable[%d]' refers to a " raise ImproperlyConfigured("'%s.list_editable[%d]' refers to a "
"field, '%s', not defiend on %s." % (cls.__name__, idx, field, model.__name__)) "field, '%s', not defiend on %s."
if field not in cls.list_display: % (cls.__name__, idx, field_name, model.__name__))
if field_name not in cls.list_display:
raise ImproperlyConfigured("'%s.list_editable[%d]' refers to " raise ImproperlyConfigured("'%s.list_editable[%d]' refers to "
"'%s' which is not defined in 'list_display'." "'%s' which is not defined in 'list_display'."
% (cls.__name__, idx, field)) % (cls.__name__, idx, field_name))
if field in cls.list_display_links: if field_name in cls.list_display_links:
raise ImproperlyConfigured("'%s' cannot be in both '%s.list_editable'" raise ImproperlyConfigured("'%s' cannot be in both '%s.list_editable'"
" and '%s.list_display_links'" " 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 = () # search_fields = ()
if hasattr(cls, 'search_fields'): if hasattr(cls, 'search_fields'):