Open WhitePoodleMoth opened 4 hours ago
@WhitePoodleMoth thank you for reporting this problem.
When attempting to block the delete option in the Django admin by overriding the delete_model
method and removing the delete action, I've noticed that while the delete permission remains active, the Accordion functionality of django-treenode
stops working.
Here's the code I'm using:
from django.core.exceptions import PermissionDenied
from django.contrib import admin
from treenode.admin import TreeNodeModelAdmin
from treenode.forms import TreeNodeForm
from .models import Category
class CategoryAdmin(TreeNodeModelAdmin):
# set the changelist display mode: 'accordion', 'breadcrumbs' or 'indentation' (default)
# when changelist results are filtered by a querystring,
# 'breadcrumbs' mode will be used (to preserve data display integrity)
treenode_display_mode = TreeNodeModelAdmin.TREENODE_DISPLAY_MODE_ACCORDION
# treenode_display_mode = TreeNodeModelAdmin.TREENODE_DISPLAY_MODE_BREADCRUMBS
# treenode_display_mode = TreeNodeModelAdmin.TREENODE_DISPLAY_MODE_INDENTATION
# use TreeNodeForm to automatically exclude invalid parent choices
form = TreeNodeForm
# def has_delete_permission(self, request, obj=None):
# return False
# def delete_model(self, request, obj):
# raise PermissionDenied("You do not have permission to delete this record.")
def get_actions(self, request):
actions = super().get_actions(request)
if 'delete_selected' in actions:
del actions['delete_selected']
return actions
admin.site.register(Category, CategoryAdmin)
Despite removing the delete action from the admin interface, the Accordion does not function properly. It appears that the removal of the delete action might be causing this issue.
After blocking the delete option in the Django admin and adding a placeholder action, I found that the Accordion functionality in django-treenode
is working correctly again.
It appears that the issue was not with the delete operation itself, but rather with having no actions available. By ensuring the delete permissions are restricted and adding a simple placeholder action, the Accordion feature is now functional.
Here’s the implementation:
from django.contrib import admin
from treenode.admin import TreeNodeModelAdmin
from treenode.forms import TreeNodeForm
from .models import Category
class CategoryAdmin(TreeNodeModelAdmin):
# Set the changelist display mode: 'accordion', 'breadcrumbs' or 'indentation' (default)
treenode_display_mode = TreeNodeModelAdmin.TREENODE_DISPLAY_MODE_ACCORDION
# Use TreeNodeForm to automatically exclude invalid parent choices
form = TreeNodeForm
# Define the actions available in the admin interface
actions = ['placeholder_action'] # Keeping only the placeholder action
def has_delete_permission(self, request, obj=None):
return False
def placeholder_action(self, request, queryset):
"""
A placeholder action to demonstrate action functionality.
"""
pass
admin.site.register(Category, CategoryAdmin)
Python version
3.12.6
Django version
5.1.1
Package version
0.22.1
Current behavior (bug description)
When
has_delete_permission
is set toFalse
in the Django admin for my model, the Accordion functionality ofdjango-treenode
stops working. The Accordion does not expand, and it remains with the default name without any options to expand.Expected behavior
I expect that even when the delete permission is disabled, the Accordion should function normally, allowing for expansion and proper display of tree nodes.
Upvote & Fund