@@ -468,3 +468,56 @@ Example with depth-limited queryset:
468
468
469
469
This is particularly useful for creating expandable tree interfaces or
470
470
rendering only portions of large trees for performance.
471
+
472
+
473
+ Django Admin Integration
474
+ ~~~~~~~~~~~~~~~~~~~~~~~~
475
+
476
+ django-tree-queries includes a ``TreeAdmin `` class for Django's admin interface
477
+ that provides an intuitive tree management experience with drag-and-drop style
478
+ node moving capabilities.
479
+
480
+ Installation
481
+ ------------
482
+
483
+ To use the admin functionality, install with the ``admin `` extra:
484
+
485
+ .. code-block :: bash
486
+
487
+ pip install django-tree-queries[admin]
488
+
489
+ Usage
490
+ -----
491
+
492
+ .. code-block :: python
493
+
494
+ from django.contrib import admin
495
+ from tree_queries.admin import TreeAdmin
496
+ from .models import Category
497
+
498
+ @admin.register (Category)
499
+ class CategoryAdmin (TreeAdmin ):
500
+ list_display = [* TreeAdmin.list_display, " name" , " is_active" ]
501
+ position_field = " position" # Optional: field used for sibling ordering
502
+
503
+ The ``TreeAdmin `` provides:
504
+
505
+ - **Tree visualization **: Nodes are displayed with indentation and visual tree structure
506
+ - **Collapsible nodes **: Click to expand/collapse branches for better navigation
507
+ - **Node moving **: Cut and paste nodes to reorganize the tree structure
508
+ - **Flexible ordering **: Supports both ordered (with position field) and unordered trees
509
+ - **Root moves **: Direct "move to root" buttons for trees without sibling ordering
510
+
511
+ **Configuration: **
512
+
513
+ - Set ``position_field `` to the field name used for positioning siblings (e.g., ``"position" ``, ``"order" ``)
514
+ - Leave ``position_field = None `` for trees positioned by other criteria (pk, name, etc.)
515
+ - The admin automatically adapts its interface based on whether positioning is controllable
516
+
517
+ **Required list_display columns: **
518
+
519
+ - ``collapse_column ``: Shows expand/collapse toggles
520
+ - ``indented_title ``: Displays the tree structure with indentation
521
+ - ``move_column ``: Provides move controls (cut, paste, move-to-root)
522
+
523
+ These are included by default in ``TreeAdmin.list_display ``.
0 commit comments