Ticket #4009: admin_list_filter.diff
File admin_list_filter.diff, 2.0 KB (added by , 18 years ago) |
---|
-
core/management.py
927 927 from django.db import models, connection 928 928 from django.db.models.loading import get_app_errors 929 929 from django.db.models.fields.related import RelatedObject 930 from django.db.models.query import LOOKUP_SEPARATOR 930 931 931 932 e = ModelErrorCollection(outfile) 932 933 … … 1077 1078 e.add(opts, '"admin.list_filter", if given, must be set to a list or tuple.') 1078 1079 else: 1079 1080 for fn in opts.admin.list_filter: 1081 # Break the entry up using the lookup separator, and 1082 # make sure each one points to a valid field. 1083 field_lookups = fn.split(LOOKUP_SEPARATOR) 1080 1084 try: 1081 f = opts.get_field(fn) 1085 f = opts.get_field(field_lookups[0]) 1086 if len(field_lookups) > 1: 1087 if not f.rel: 1088 e.add(opts, '"admin.list_filter" refers to %r, which contains a non-related field.' % fn) 1089 for field_name in field_lookups[1:]: 1090 model = f.rel.to 1091 f = model._meta.get_field(field_name) 1092 if not f.rel: 1093 e.add(opts, '"admin.list_filter" refers to %r, which contains a non-related field.' % fn) 1082 1094 except models.FieldDoesNotExist: 1083 e.add(opts, '"admin.list_filter" refers to %r, which isn\'t a field.' % fn) 1095 if not hasattr(cls, field_lookups[0]): 1096 e.add(opts, '"admin.list_filter" refers to %r, which isn\'t a field.' % fn) 1084 1097 # date_hierarchy 1085 1098 if opts.admin.date_hierarchy: 1086 1099 try: