Add help_text support to custom ModelAdmin read-only fields
- Dominant language
- No language data
- Stars
- 188
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Description
### Code of Conduct
- [x] I agree to follow Django's Code of Conduct
### Feature Description
Adding standard Django Admin help_text to a custom read-only field currently requires [various verbose hacks](https://stackoverflow.com/questions/45535289/add-help-text-to-django-admin-field), despite the presence of the `@admin.display` decorator which can already override its display label and so on.
The `help_text` kwarg below is NOT yet implemented in Django:
```python
@admin.register
class MyModelAdmin(admin.ModelAdmin):
readonly_fields = ["status_pretty"]
@admin.display(description="Status", help_text="The last known state of the thing")
def status_pretty(self, obj):
color = "green"
if obj.status == MyModel.Status.ERROR:
color = "red"
return mark_safe(f"{obj.status.title()}")
```
A small +21/-3 patch implements this feature here, following exactly the current implementation of `short_description`, etc.
https://github.com/pphysch/django/tree/add-help-text-for-custom-admin-fields
### Problem
This small feature follows existing conventions to provide a concise way to specify standard help_text for custom ModelAdmin read-only fields, allowing Django users to write cleaner code and avoid verbose workarounds.
### Request or proposal
proposal
### Additional Details
Working patch is implemented here: https://github.com/pphysch/django/tree/add-help-text-for-custom-admin-fields
Note that specifying `@admin.display(help_text="...")` on an actual model field will NOT override the model field's `help_text`. This could be changed easily, but this is the default behavior that minimizes changes to the Django code base. This change is mainly for custom ModelAdmin attributes that are *not* derived from the Model's actual fields and hence don't yet have any `help_text` to configure.
### Implementation Suggestions
See the fork for the small +21/-3 patch.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.