-
Notifications
You must be signed in to change notification settings - Fork 309
Description
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")