Skip to content

Commit dd6962c

Browse files
committed
Add wagtail@8 fallback imports re/ warnings
1 parent 28b5378 commit dd6962c

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ Much of this library was built atop of the work of others, specifically:
205205

206206
When upgrading this, ensure both `InstanceSelectorPanel` and `InstanceSelectorBlock` are tested manually via the example projects as they use different JavaScript integration approaches.
207207

208+
The example project is setup for testing via:
209+
- `Shop` model admin for `InstanceSelectorBlock` testing.
210+
- `Product` model admin `InstanceSelectorPanel` testing.
211+
208212
### Run tests
209213

210214
```

example/example_project/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@
116116

117117
USE_TZ = True
118118

119+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
120+
119121

120122
# Static files (CSS, JavaScript, Images)
121123
# https://docs.djangoproject.com/en/2.2/howto/static-files/

instance_selector/blocks.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
from wagtail.blocks import ChooserBlock
33
from wagtail.blocks.field_block import FieldBlockAdapter
44
from wagtail.coreutils import resolve_model_string
5-
from wagtail.telepath import register
5+
6+
# Handle Wagtail 8.0+ import location changes
7+
try:
8+
from wagtail.admin.telepath import register
9+
except ImportError:
10+
# Fallback for Wagtail < 8.0
11+
from wagtail.telepath import register
612

713
from instance_selector.registry import registry
814
from instance_selector.widgets import InstanceSelectorWidget

instance_selector/widgets.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
from django.urls import reverse
66
from django.utils.safestring import mark_safe
77
from django.utils.translation import gettext_lazy as _
8-
from wagtail.telepath import register
9-
from wagtail.widget_adapters import WidgetAdapter
8+
9+
# Handle Wagtail 8.0+ import location changes
10+
try:
11+
from wagtail.admin.telepath import register
12+
from wagtail.admin.telepath.widgets import WidgetAdapter
13+
except ImportError:
14+
# Fallback for Wagtail < 8.0
15+
from wagtail.telepath import register
16+
from wagtail.widget_adapters import WidgetAdapter
1017

1118
from instance_selector.constants import OBJECT_PK_PARAM
1219
from instance_selector.registry import registry

0 commit comments

Comments
 (0)