|
2 | 2 | The parent admin displays the list view of the base model. |
3 | 3 | """ |
4 | 4 | import sys |
5 | | -import warnings |
6 | 5 |
|
7 | | -from django.conf.urls import url |
8 | 6 | from django.contrib import admin |
9 | 7 | from django.contrib.admin.helpers import AdminErrorList, AdminForm |
10 | 8 | from django.contrib.admin.templatetags.admin_urls import add_preserved_filters |
11 | 9 | from django.contrib.contenttypes.models import ContentType |
12 | | -from django.core.exceptions import PermissionDenied |
| 10 | +from django.core.exceptions import PermissionDenied, ImproperlyConfigured |
| 11 | +from django.db import models |
13 | 12 | from django.http import Http404, HttpResponseRedirect |
14 | 13 | from django.template.response import TemplateResponse |
15 | 14 | from django.urls import RegexURLResolver |
@@ -39,11 +38,11 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin): |
39 | 38 | A admin interface that can displays different change/delete pages, depending on the polymorphic model. |
40 | 39 | To use this class, one attribute need to be defined: |
41 | 40 |
|
42 | | - * :attr:`child_models` should be a list of (Model, Admin) tuples |
| 41 | + * :attr:`child_models` should be a list models. |
43 | 42 |
|
44 | 43 | Alternatively, the following methods can be implemented: |
45 | 44 |
|
46 | | - * :func:`get_child_models` should return a list of (Model, ModelAdmin) tuples |
| 45 | + * :func:`get_child_models` should return a list of models. |
47 | 46 | * optionally, :func:`get_child_type_choices` can be overwritten to refine the choices for the add dialog. |
48 | 47 |
|
49 | 48 | This class needs to be inherited by the model admin base class that is registered in the site. |
@@ -79,6 +78,17 @@ def _lazy_setup(self): |
79 | 78 | return |
80 | 79 |
|
81 | 80 | self._child_models = self.get_child_models() |
| 81 | + |
| 82 | + # Make absolutely sure that the child models don't use the old 0.9 format, |
| 83 | + # as of polymorphic 1.4 this deprecated configuration is no longer supported. |
| 84 | + # Instead, register the child models in the admin too. |
| 85 | + if self._child_models and not issubclass(self._child_models[0], models.Model): |
| 86 | + raise ImproperlyConfigured( |
| 87 | + "Since django-polymorphic 1.4, the `child_models` attribute " |
| 88 | + "and `get_child_models()` method should be a list of models only.\n" |
| 89 | + "The model-admin class should be registered in the regular Django admin." |
| 90 | + ) |
| 91 | + |
82 | 92 | self._child_admin_site = self.admin_site |
83 | 93 | self._is_setup = True |
84 | 94 |
|
|
0 commit comments