|
1 | 1 | import json |
2 | 2 |
|
3 | 3 | from django import forms |
4 | | -from django.contrib import messages |
| 4 | +from django.conf import settings |
| 5 | +from django.contrib import admin, messages |
5 | 6 | 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 |
7 | 12 | from django.core.exceptions import ValidationError |
8 | 13 | from django.db.models import F |
9 | 14 | from django.http import HttpResponse |
@@ -58,6 +63,18 @@ class NodeAdmin(TreeAdmin): |
58 | 63 | list_display = ["collapse_column", "indented_title", "move_column"] |
59 | 64 | list_display_links = ["indented_title"] |
60 | 65 |
|
| 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 | + |
61 | 78 | @csrf_protect_m |
62 | 79 | def changelist_view(self, request, **kwargs): |
63 | 80 | from js_asset.js import JS # noqa: PLC0415 |
@@ -120,6 +137,7 @@ def indented_title(self, instance, *, ellipsize=True): |
120 | 137 |
|
121 | 138 | indented_title.short_description = _("title") |
122 | 139 |
|
| 140 | + @admin.display(description=_("move")) |
123 | 141 | def move_column(self, instance): |
124 | 142 | """ |
125 | 143 | Show a ``move`` link which leads to a separate page where the move |
@@ -165,8 +183,6 @@ def move_column(self, instance): |
165 | 183 | options, |
166 | 184 | ) |
167 | 185 |
|
168 | | - move_column.short_description = _("move") |
169 | | - |
170 | 186 | def get_urls(self): |
171 | 187 | """ |
172 | 188 | Add our own ``move`` view. |
|
0 commit comments