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.
* cc: Nick Pope (added)
* status: new => closed
* resolution: => wontfix
Comment:
Thanks for this proposition, however IMO we have enough ways to customize
the admin changelist. The Django Admin is not a
[https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#module-
django.contrib.admin universal tool for building an app]. You can create
your own decorator if you need a shortcut for this.
--
Ticket URL: <https://code.djangoproject.com/ticket/32804#comment:1>