Skip to content

Conversation

@jgregory-valence
Copy link

The previous README had instructions about preventing the deletion of inlined models by overriding the has_delete_permission method on a custom subclass of the appropriate StackedInline or TabularInline class, and then passing that subclass as the admin_class option of inline_reverse. However, that method no longer works with newer versions of Django (at least with Django 4.2 and later).

This commit updates the ReverseInlineModelAdmin class to determine can_delete in the same way that Django's InlineModelAdmin currently does, and then passes that into the custom formset factory. In that way, consumers of this library can simply set the can_delete option directly on their inline_reverse specification without subclassing one of the built-in InlineModelAdmin implementations.

Note that this approach was necessary because the custom formset factory in django_reverse_admin lives outside of the ReverseInlineModelAdmin class, and doesn't have access to the parent class' can_delete property and has_delete_permission method.

The previous README had instructions about preventing the deletion of
inlined models by overriding the `has_delete_permission` method on a
custom subclass of the appropriate `StackedInline` or `TabularInline`
class, and then passing that subclass as the `admin_class` option of
`inline_reverse`.  However, that method no longer works with newer
versions of Django (at least with Django 4.2 and later).

This commit updates the `ReverseInlineModelAdmin` class to determine
`can_delete` in the same way that Django's `InlineModelAdmin` currently
does, and then passes that into the custom formset factory.  In that
way, consumers of this library can simply set the `can_delete` option
directly on their `inline_reverse` specification without subclassing one
of the built-in `InlineModelAdmin` implementations.

Note that this approach was necessary because the custom formset factory
in `django_reverse_admin` lives outside of the `ReverseInlineModelAdmin`
class, and doesn't have access to the parent class' `can_delete`
property and `has_delete_permission` method.
@jgregory-valence jgregory-valence force-pushed the fix-can-delete-boolean branch from 61dc102 to d4df21c Compare July 11, 2025 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants