Clickable links to related readonly M2M instances in the admin
- 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
The feature is a small change in the `AdminReadonlyField`'s `contents` method: Instead of joining the string representation of the related objects, join the admin_url's of them, just like with the ForeignKeys (or OneToOneFields).
### Problem
When a ManyToManyField is readonly in a ModelAdmin, a list of the string representations of the related objects is shown. That isn't very useful, the idea would be to have a clickable link to be able to view the related object.
### Request or proposal
proposal
### Additional Details
_No response_
### Implementation Suggestions
In the `AdminReadonlyField.contents` method, when the field is a many to many relationship and the value is set, the code is as follows:
```python
if isinstance(f.remote_field, ManyToManyRel) and value is not None:
result_repr = ", ".join(map(str, value.all()))
```
The change would leave the code similar to this:
```python
if isinstance(f.remote_field, ManyToManyRel) and value is not None:
result_repr = "\n".join(
map(
lambda obj: self.get_admin_url(f.remote_field, obj),
value.all(),
)
)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.