Ticket #5374: modelamin.patch
File modelamin.patch, 5.4 KB (added by , 17 years ago) |
---|
-
django/core/management/validation.py
1 1 import sys 2 2 from django.core.management.color import color_style 3 from django.contrib import admin 3 4 4 5 class ModelErrorCollection: 5 6 def __init__(self, outfile=sys.stdout): … … 132 133 e.add(opts, "Reverse query name for m2m field '%s' clashes with related field '%s.%s'. Add a related_name argument to the definition for '%s'." % (f.name, rel_opts.object_name, r.get_accessor_name(), f.name)) 133 134 134 135 # Check admin attribute. 135 if opts.admin is not None: 136 if cls in admin.site._registry: 137 admin_opts = admin.site._registry[cls] 136 138 # prepopulated_fields 137 if not isinstance( opts.admin.prepopulated_fields, dict):138 e.add(opts, ' "%s": prepopulated_fields should be a dictionary.' % f.name)139 if not isinstance(admin_opts.prepopulated_fields, dict): 140 e.add(opts, 'admin: prepopulated_fields should be a dictionary.') 139 141 else: 140 for field_name, field_list in opts.admin.prepopulated_fields.items():142 for field_name, field_list in admin_opts.prepopulated_fields.items(): 141 143 if not isinstance(field_list, (list, tuple)): 142 e.add(opts, ' "%s": prepopulated_fields "%s" value should be a list or tuple.' % (f.name,field_name))144 e.add(opts, 'admin: prepopulated_fields "%s" value should be a list or tuple.' % (field_name)) 143 145 144 146 # list_display 145 if not isinstance( opts.admin.list_display, (list, tuple)):147 if not isinstance(admin_opts.list_display, (list, tuple)): 146 148 e.add(opts, '"admin.list_display", if given, must be set to a list or tuple.') 147 149 else: 148 for fn in opts.admin.list_display:150 for fn in admin_opts.list_display: 149 151 try: 150 152 f = opts.get_field(fn) 151 153 except models.FieldDoesNotExist: … … 155 157 if isinstance(f, models.ManyToManyField): 156 158 e.add(opts, '"admin.list_display" doesn\'t support ManyToManyFields (%r).' % fn) 157 159 # list_display_links 158 if opts.admin.list_display_links and not opts.admin.list_display:160 if admin_opts.list_display_links and not admin_opts.list_display: 159 161 e.add(opts, '"admin.list_display" must be defined for "admin.list_display_links" to be used.') 160 if not isinstance( opts.admin.list_display_links, (list, tuple)):162 if not isinstance(admin_opts.list_display_links, (list, tuple)): 161 163 e.add(opts, '"admin.list_display_links", if given, must be set to a list or tuple.') 162 164 else: 163 for fn in opts.admin.list_display_links:165 for fn in admin_opts.list_display_links: 164 166 try: 165 167 f = opts.get_field(fn) 166 168 except models.FieldDoesNotExist: 167 169 if not hasattr(cls, fn): 168 170 e.add(opts, '"admin.list_display_links" refers to %r, which isn\'t an attribute, method or property.' % fn) 169 if fn not in opts.admin.list_display:171 if fn not in admin_opts.list_display: 170 172 e.add(opts, '"admin.list_display_links" refers to %r, which is not defined in "admin.list_display".' % fn) 171 173 # list_filter 172 if not isinstance( opts.admin.list_filter, (list, tuple)):174 if not isinstance(admin_opts.list_filter, (list, tuple)): 173 175 e.add(opts, '"admin.list_filter", if given, must be set to a list or tuple.') 174 176 else: 175 for fn in opts.admin.list_filter:177 for fn in admin_opts.list_filter: 176 178 try: 177 179 f = opts.get_field(fn) 178 180 except models.FieldDoesNotExist: 179 181 e.add(opts, '"admin.list_filter" refers to %r, which isn\'t a field.' % fn) 180 182 # date_hierarchy 181 if opts.admin.date_hierarchy:183 if admin_opts.date_hierarchy: 182 184 try: 183 f = opts.get_field( opts.admin.date_hierarchy)185 f = opts.get_field(admin_opts.date_hierarchy) 184 186 except models.FieldDoesNotExist: 185 e.add(opts, '"admin.date_hierarchy" refers to %r, which isn\'t a field.' % opts.admin.date_hierarchy) 187 e.add(opts, '"admin.date_hierarchy" refers to %r, which isn\'t a field.' % admin_opts.date_hierarchy) 188 # raw_id_admin 189 if not isinstance(admin_opts.raw_id_fields, (list, tuple)): 190 e.add(opts, '"admin.raw_id_fields", if given, must be set to a list or tuple.') 191 else: 192 for fn in admin_opts.raw_id_fields: 193 try: 194 f = opts.get_field(fn) 195 except models.FieldDoesNotExist: 196 e.add(opts, '"admin.raw_id_fields" refers to %r, which isn\'t a field.' % fn) 186 197 198 187 199 # Check ordering attribute. 188 200 if opts.ordering: 189 201 for field_name in opts.ordering: