Improved model validator to check admin.list_filter and type-check admin.list_display

git-svn-id: http://code.djangoproject.com/svn/django/trunk@784 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-10-06 01:41:54 +00:00
parent c3fa47edb8
commit 8dda2aeaa3
1 changed files with 23 additions and 10 deletions

View File

@ -548,6 +548,10 @@ def get_validation_errors(outfile):
if opts.admin is not None: if opts.admin is not None:
if not isinstance(opts.admin, meta.Admin): if not isinstance(opts.admin, meta.Admin):
e.add(opts, '"admin" attribute, if given, must be set to a meta.Admin() instance.') e.add(opts, '"admin" attribute, if given, must be set to a meta.Admin() instance.')
else:
# list_display
if not isinstance(opts.admin.list_display, (list, tuple)):
e.add(opts, '"admin.list_display", if given, must be set to a list or tuple.')
else: else:
for fn in opts.admin.list_display: for fn in opts.admin.list_display:
try: try:
@ -559,6 +563,15 @@ def get_validation_errors(outfile):
else: else:
if isinstance(f, meta.ManyToManyField): if isinstance(f, meta.ManyToManyField):
e.add(opts, '"admin.list_display" doesn\'t support ManyToManyFields (%r).' % fn) e.add(opts, '"admin.list_display" doesn\'t support ManyToManyFields (%r).' % fn)
# list_filter
if not isinstance(opts.admin.list_filter, (list, tuple)):
e.add(opts, '"admin.list_filter", if given, must be set to a list or tuple.')
else:
for fn in opts.admin.list_filter:
try:
f = opts.get_field(fn)
except meta.FieldDoesNotExist:
e.add(opts, '"admin.list_filter" refers to %r, which isn\'t a field.' % fn)
# Check ordering attribute. # Check ordering attribute.
if opts.ordering: if opts.ordering: