Skip to content

Setting highlight_deleted_field.short_description mistakenly affects all subclasses of SafeDeleteAdmin #218

@sjdemartini

Description

@sjdemartini

Thanks for the great package! I noticed one issue using SafeDeleteAdmin and the highlight_deleted_field option, after following the example in the docs:

class ContactAdmin(SafeDeleteAdmin):
   list_display = (highlight_deleted, "highlight_deleted_field", "first_name", "last_name", "email") + SafeDeleteAdmin.list_display
   list_filter = ("last_name", SafeDeleteAdminFilter,) + SafeDeleteAdmin.list_filter

   field_to_highlight = "id"

ContactAdmin.highlight_deleted_field.short_description = ContactAdmin.field_to_highlight

This introduces a bug in that it will override the SafeDeleteAdmin's highlight_deleted_field.short_description, so all subclasses will end up with the same value, since it's an attribute on the superclass's highlight_deleted_field method. Even if multiple subclasses attempt to set the attribute, like ContactAdmin.highlight_deleted_field.short_description = ContactAdmin.field_to_highlight and OtherAdmin.highlight_deleted_field.short_description = "Foo", the one defined last will override all others.


One workaround right now is to redefine the highlight_deleted_field in every subclass, so that you can attach an attribute that doesn't clobber other usage of SafeDeleteAdmin, like:

class ContactAdmin(SafeDeleteAdmin):
    list_display = (highlight_deleted, "highlight_deleted_field", "first_name", "last_name", "email") + SafeDeleteAdmin.list_display
    list_filter = ("last_name", SafeDeleteAdminFilter,) + SafeDeleteAdmin.list_filter

    field_to_highlight = "id"

    def highlight_deleted_field(self, *args, **kwargs):
        return super().highlight_deleted_field(*args, **kwargs)

    highlight_deleted_field.short_description = "ID"

but this feels pretty messy. Is it possible to change SafeDeleteAdmin such that it references some other field on the class like:

class ContactAdmin(SafeDeleteAdmin):
    field_to_highlight = "id"
    field_to_highlight_short_description = "ID"  # <-- new field here

rather than needing to add an attribute to the method?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions