Hello!
Really useful idea, I think! 2 points about it:
1. Syntax
I would also remove the html from the models, but probably in this way:
class Hammer(models.Model):
...
Meta:
icon = ModelIcon("🔨")
There would be something like
ModelIcon.as_html(self, model_name:str) -> str:
"""returns whatever html should be used in the admin"""
or a ModelIcon.set_text(self, text: str) and we'd use a simple
str(model_icon) in the templates.
That way, it could be extended easily in a
FontAwesomeModelIcon("fa-hammer") and a BootstrapModelIcon("bi-hammer")
for example, and maybe get whatever extra arguments they may need, like
FontAwesomeModelIcon("fa-hammer", thickness="solid").
2. Make it more widely useful
I like the fact that it's in the model itself and not in the modeladmin,
as it allows to use it elsewhere, like in the __str__ to quickly add
this visual indication of the class. Boostrap and co would have to
provide a non-html version of the icon or return an empty string though.
Le 21/02/2023 à 01:31, Marty a écrit :
I really like the idea to add just a simple 'icon' attribute. That's
quite elegant solution. Thanks, Mark! 🙂
On Monday, February 20, 2023 at 2:33:43 PM UTC+1 Jacob Rief wrote:
I agree with Adam Johnson that adding HTML to the model class is a
bit too coupled.
But I like the idea of Mark Niehues to add them to the ModelAdmin
class, although I would allow a HTML/SVG snippet rather than a CSS
class.
* How would we then handle 3rd party apps providing their own
SVG file to be used as icon?
* Shouldn't that icon definition be part of the ModelAdmin's
Media subclass?
– Jacob
--
You received this message because you are subscribed to the Google
Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/45c143cc-2716-430a-93cf-7c2a938640ccn%40googlegroups.com
<https://groups.google.com/d/msgid/django-developers/45c143cc-2716-430a-93cf-7c2a938640ccn%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
You received this message because you are subscribed to the Google Groups "Django
developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/890a79aa-578f-0b06-95cb-33f660baecd2%40brice.xyz.