Skip to content

Commit 3fe17d7

Browse files
committed
Provide helpful assistence to migrate code to new 1.0+ format
This makes sure the changes in 4dc20a0 don't cause a new range of bug reports, for things like "reverse()" no longer works.
1 parent 075f457 commit 3fe17d7

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

docs/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ Changes in git
55
--------------
66

77
* **BACKWARDS INCOMPATIBILITY:** Dropped Django 1.8 support.
8+
* **BACKWARDS INCOMPATIBILITY:** Removed old deprecated code from 1.0, thus:
9+
10+
* Import managers from ``polymorphic.managers`` (plural), not ``polymorphic.manager``.
11+
* Register child models to the admin as well using ``@admin.register()`` or ``admin.site.register()``,
12+
as this is no longer done automatically.
13+
814
* Added ``PolymorphicTypeUndefined`` exception for incomplete imported models.
915
When a data migration or import creates an polymorphic model,
1016
the ``polymorphic_ctype_id`` field should be filled in manually too.

polymorphic/admin/parentadmin.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
The parent admin displays the list view of the base model.
33
"""
44
import sys
5-
import warnings
65

7-
from django.conf.urls import url
86
from django.contrib import admin
97
from django.contrib.admin.helpers import AdminErrorList, AdminForm
108
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
119
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
1312
from django.http import Http404, HttpResponseRedirect
1413
from django.template.response import TemplateResponse
1514
from django.urls import RegexURLResolver
@@ -39,11 +38,11 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
3938
A admin interface that can displays different change/delete pages, depending on the polymorphic model.
4039
To use this class, one attribute need to be defined:
4140
42-
* :attr:`child_models` should be a list of (Model, Admin) tuples
41+
* :attr:`child_models` should be a list models.
4342
4443
Alternatively, the following methods can be implemented:
4544
46-
* :func:`get_child_models` should return a list of (Model, ModelAdmin) tuples
45+
* :func:`get_child_models` should return a list of models.
4746
* optionally, :func:`get_child_type_choices` can be overwritten to refine the choices for the add dialog.
4847
4948
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):
7978
return
8079

8180
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+
8292
self._child_admin_site = self.admin_site
8393
self._is_setup = True
8494

0 commit comments

Comments
 (0)