#32804: Add 'link' attribute to admin display function to enable custom link
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
Skrattoune |
Type: New | Status: new
feature |
Component: | Version: 3.2
contrib.admin | Keywords: admin, hyperlink,
Severity: Normal | decorator, display
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hi, The new admin.display decorator is great for decreasing the burden for
declaring custom admin pages.
What would be even greater for my personal django usage, would be to add
directly from the display decorator the possibility to associate a custom
link to the displayed attribute.
For instance, instead of having to declare in the AdminModel:
{{{
@admin.display(ordering='-nb_variants', description='nb_variants')
def _nb_variants(self, obj):
# adding a link to open a new tab with the result
return format_html(f'<a
href="/admin/puzzles/puzzle/?uncolored_puzzle_id={obj.uncolored_puzzle_id}"
target="_blank">{obj.nb_variants}</a>')
}}}
to enable declaring directly inside the model at the property or method
level:
{{{
def href_to_variants(self):
return
f"/admin/puzzles/puzzle/?uncolored_puzzle_id={self.uncolored_puzzle_id}"
@cached_property
@admin.display(
link='href_to_variants',
target_blank=True,
)
def nb_variants(self):
return self.variants.count()
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32804>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/053.640f0ecbc25e37d041ecdcc34ebf5996%40djangoproject.com.