| 146 | | # Check admin attribute. |
|---|
| 147 | | if opts.admin is not None: |
|---|
| 148 | | # prepopulated_fields |
|---|
| 149 | | if not isinstance(opts.admin.prepopulated_fields, dict): |
|---|
| 150 | | e.add(opts, '"%s": prepopulated_fields should be a dictionary.' % f.name) |
|---|
| 151 | | else: |
|---|
| 152 | | for field_name, field_list in opts.admin.prepopulated_fields.items(): |
|---|
| 153 | | if not isinstance(field_list, (list, tuple)): |
|---|
| 154 | | e.add(opts, '"%s": prepopulated_fields "%s" value should be a list or tuple.' % (f.name, field_name)) |
|---|
| 155 | | |
|---|
| 156 | | # list_display |
|---|
| 157 | | if not isinstance(opts.admin.list_display, (list, tuple)): |
|---|
| 158 | | e.add(opts, '"admin.list_display", if given, must be set to a list or tuple.') |
|---|
| 159 | | else: |
|---|
| 160 | | for fn in opts.admin.list_display: |
|---|
| 161 | | try: |
|---|
| 162 | | f = opts.get_field(fn) |
|---|
| 163 | | except models.FieldDoesNotExist: |
|---|
| 164 | | if not hasattr(cls, fn): |
|---|
| 165 | | e.add(opts, '"admin.list_display" refers to %r, which isn\'t an attribute, method or property.' % fn) |
|---|
| 166 | | else: |
|---|
| 167 | | if isinstance(f, models.ManyToManyField): |
|---|
| 168 | | e.add(opts, '"admin.list_display" doesn\'t support ManyToManyFields (%r).' % fn) |
|---|
| 169 | | # list_display_links |
|---|
| 170 | | if opts.admin.list_display_links and not opts.admin.list_display: |
|---|
| 171 | | e.add(opts, '"admin.list_display" must be defined for "admin.list_display_links" to be used.') |
|---|
| 172 | | if not isinstance(opts.admin.list_display_links, (list, tuple)): |
|---|
| 173 | | e.add(opts, '"admin.list_display_links", if given, must be set to a list or tuple.') |
|---|
| 174 | | else: |
|---|
| 175 | | for fn in opts.admin.list_display_links: |
|---|
| 176 | | try: |
|---|
| 177 | | f = opts.get_field(fn) |
|---|
| 178 | | except models.FieldDoesNotExist: |
|---|
| 179 | | if not hasattr(cls, fn): |
|---|
| 180 | | e.add(opts, '"admin.list_display_links" refers to %r, which isn\'t an attribute, method or property.' % fn) |
|---|
| 181 | | if fn not in opts.admin.list_display: |
|---|
| 182 | | e.add(opts, '"admin.list_display_links" refers to %r, which is not defined in "admin.list_display".' % fn) |
|---|
| 183 | | # list_filter |
|---|
| 184 | | if not isinstance(opts.admin.list_filter, (list, tuple)): |
|---|
| 185 | | e.add(opts, '"admin.list_filter", if given, must be set to a list or tuple.') |
|---|
| 186 | | else: |
|---|
| 187 | | for fn in opts.admin.list_filter: |
|---|
| 188 | | try: |
|---|
| 189 | | f = opts.get_field(fn) |
|---|
| 190 | | except models.FieldDoesNotExist: |
|---|
| 191 | | e.add(opts, '"admin.list_filter" refers to %r, which isn\'t a field.' % fn) |
|---|
| 192 | | # date_hierarchy |
|---|
| 193 | | if opts.admin.date_hierarchy: |
|---|
| 194 | | try: |
|---|
| 195 | | f = opts.get_field(opts.admin.date_hierarchy) |
|---|
| 196 | | except models.FieldDoesNotExist: |
|---|
| 197 | | e.add(opts, '"admin.date_hierarchy" refers to %r, which isn\'t a field.' % opts.admin.date_hierarchy) |
|---|
| 198 | | |
|---|