Improved model validator so that it validates admin.list_display values

git-svn-id: http://code.djangoproject.com/svn/django/trunk@650 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-09-20 02:48:25 +00:00
parent 1d65ba62db
commit 7dfb86724d
1 changed files with 14 additions and 2 deletions

View File

@ -537,8 +537,20 @@ def get_validation_errors(outfile):
e.add(opts, '"%s" field: "choices" should be a sequence of two-tuples.' % f.name)
# Check admin attribute.
if opts.admin is not None and not isinstance(opts.admin, meta.Admin):
e.add(opts, '"admin" attribute, if given, must be set to a meta.Admin() instance.')
if opts.admin is not None:
if not isinstance(opts.admin, meta.Admin):
e.add(opts, '"admin" attribute, if given, must be set to a meta.Admin() instance.')
else:
for fn in opts.admin.list_display:
try:
f = opts.get_field(fn)
except meta.FieldDoesNotExist:
klass = opts.get_model_module().Klass
if not hasattr(klass, fn) or not callable(getattr(klass, fn)):
e.add(opts, '"admin.list_display" refers to %r, which isn\'t a field or method.' % fn)
else:
if isinstance(f, meta.ManyToManyField):
e.add(opts, '"admin.list_display" doesn\'t support ManyToManyFields (%r).' % fn)
# Check ordering attribute.
if opts.ordering: