WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 83abc21

Browse files
committed
Verify that tree_queries has been added to INSTALLED_APPS when using TreeAdmin
1 parent fd0eb96 commit 83abc21

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Next version
1010
- Added an example migration to the documentation for migrating from
1111
django-mptt to django-tree-queries. Thanks to @felixmm for providing this!
1212
- Avoided fetching ancestors of nodes without parents. Thanks to @felixmm!
13+
- Added a system check which verifies that ``"tree_queries"`` has been added to
14+
``INSTALLED_APPS`` if using the ``TreeAdmin`` model admin class.
1315

1416

1517
0.21 (2025-09-16)

tree_queries/admin.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import json
22

33
from django import forms
4-
from django.contrib import messages
4+
from django.conf import settings
5+
from django.contrib import admin, messages
56
from django.contrib.admin import ModelAdmin, SimpleListFilter, display, helpers
6-
from django.contrib.admin.options import IncorrectLookupParameters, csrf_protect_m
7+
from django.contrib.admin.options import (
8+
IncorrectLookupParameters,
9+
csrf_protect_m,
10+
)
11+
from django.core import checks
712
from django.core.exceptions import ValidationError
813
from django.db.models import F
914
from django.http import HttpResponse
@@ -58,6 +63,18 @@ class NodeAdmin(TreeAdmin):
5863
list_display = ["collapse_column", "indented_title", "move_column"]
5964
list_display_links = ["indented_title"]
6065

66+
def check(self, **kwargs):
67+
errors = super().check(**kwargs)
68+
if "tree_queries" not in settings.INSTALLED_APPS:
69+
errors.append(
70+
checks.Error(
71+
'"tree_queries" must be in INSTALLED_APPS.',
72+
obj=self.__class__,
73+
id="tree_queries.E001",
74+
)
75+
)
76+
return errors
77+
6178
@csrf_protect_m
6279
def changelist_view(self, request, **kwargs):
6380
from js_asset.js import JS # noqa: PLC0415
@@ -120,6 +137,7 @@ def indented_title(self, instance, *, ellipsize=True):
120137

121138
indented_title.short_description = _("title")
122139

140+
@admin.display(description=_("move"))
123141
def move_column(self, instance):
124142
"""
125143
Show a ``move`` link which leads to a separate page where the move
@@ -165,8 +183,6 @@ def move_column(self, instance):
165183
options,
166184
)
167185

168-
move_column.short_description = _("move")
169-
170186
def get_urls(self):
171187
"""
172188
Add our own ``move`` view.

0 commit comments

Comments
 (0)