-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accordion stops working when there are no actions in the admin panel or when the user lacks delete permissions #172
Comments
@whitepoodlemoth thank you for reporting this problem. |
When attempting to block the delete option in the Django admin by overriding the 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 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) |
@whitepoodlemoth thank you for the debugging you did, very useful for fixing this issue! |
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
The text was updated successfully, but these errors were encountered: