From cb330bc6e8875930a8b02a0a6824746eabaa404f Mon Sep 17 00:00:00 2001 From: smilerz Date: Tue, 28 Sep 2021 10:09:13 -0500 Subject: [PATCH] added Admin function to sort trees --- cookbook/admin.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cookbook/admin.py b/cookbook/admin.py index 2146629c..726563c3 100644 --- a/cookbook/admin.py +++ b/cookbook/admin.py @@ -89,9 +89,18 @@ class SyncLogAdmin(admin.ModelAdmin): admin.site.register(SyncLog, SyncLogAdmin) +@admin.action(description='Sort tree by name') +def sort_tree(modeladmin, request, queryset): + modeladmin.model.node_order_by = ['name'] + with scopes_disabled(): + Keyword.fix_tree(fix_paths=True) + modeladmin.model.node_order_by = [] + + class KeywordAdmin(TreeAdmin): form = movenodeform_factory(Keyword) ordering = ('space', 'path',) + actions = [sort_tree] admin.site.register(Keyword, KeywordAdmin) @@ -138,6 +147,7 @@ admin.site.register(Unit) class FoodAdmin(TreeAdmin): form = movenodeform_factory(Keyword) ordering = ('space', 'path',) + actions = [sort_tree] admin.site.register(Food, FoodAdmin)