Skip to content

'XXXAdmin' object has no attribute 'compressed_fields' (external apps) #998

@Zerotask

Description

@Zerotask

What version of Unfold are you using?

For example: 0.45.0

What version of Django are you using?

For example: 5.1

What browser are you using?

For example: Safari (latest)

Did you checked changelog/commit history, if the bug is not already fixed?

For example: Yes

Did you searched other issues, if the bug is not already fixed?

For example: Yes

Did you checked documentation?

For example: Yes

Are you able to replicate the bug in the demo site?

No

Repository with reproduced bug

Describe your issue

When we added the package django-axes and tried to open a detail view from one of their model objects, we get this error:
AttributeError: 'AccessLogAdmin' object has no attribute 'compressed_fields'

There are 2 places in templatetags.unfold where adminform.model_admin.compressed_fields is accessed.

The issue is, that we have to create custom ModelAdmin classes with unfold and unless you do that, you'll get this error.

My suggestion is:
a) add a check for this attribute (+ maybe a log warning, that it's recommended to use unfold.admin.ModelAdmin)
b) add a more precise error message

Regarding a)
adminform.model_admin.compressed_fields -> hasattr(adminform.model_admin, "compressed_fields") and adminform.model_admin.compressed_fields
This way the detail page is at least working.

Regarding b)

if not hasattr(adminform.model_admin, "compressed_fields"):
    raise Exception(f"{adminform.model_admin} has no compressed_fields attribute. Please ensure that the model admin class is inheriting from unfold.admin.ModelAdmin")

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