Hi all, I see Wagtail has been mentioned, we actually shipped a lot of improvements to our icons support in our last release, thought I’d share a few details in case it helps in considering this for Django.
Here is Wagtail’s documentation for custom icons: https://docs.wagtail.org/en/stable/advanced_topics/icons.html. The TL;DR; is: - Icons are SVG files, registered in the CMS with a unique identifier (for example "fa-user-solid") - This makes it possible to create "icon pack" packages ("django-fontawesome", "django-myiconset"), which register large amounts of icons. And also allows for specific projects to register their own custom icon(s). - In different parts of the code (Wagtail’s ModelAdmin equivalents), we allow providing an icon identifier. - We have a set of built-in icons, most from FontAwesome, some custom. - icons are then loaded as an inline SVG "sprite" (SVG symbol elements). As an aside, the Django admin’s current iconography is in a dire need of being rebuilt. Its implementation with `img` elements and background images is really less than ideal for accessibility, because it makes it really hard to style icons according to different needs (light theme, dark theme, high contrast mode) and UI states (error, focus, etc). Cheers, Thibaud On Friday, 3 March 2023 at 15:08:24 UTC Bogdan Barna wrote: > > Hello all, > > I've joined this emailing list just to support the fellow users, of not > adding this (especially on models.Model) as per their points made. > > Thanks, > Bogdan > > On Thursday, February 23, 2023 at 5:54:44 PM UTC+2 Jacob Rief wrote: > >> On Thu, Feb 23, 2023 at 7:38 AM Brice Parent <con...@brice.xyz> wrote: >> >>> 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. >>> >>> In my opinion, Django models shall not have to specify parts of their >> representation layer, such as icons. >> This shall be left exclusively to the view layer: The ModelAdmin is such >> a candidate. >> >> 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"). >>> >>> I don't like the idea that Django becomes dependent on any >> UTF-8-Symbol/Dingbats/Emojis/Glyphicon/Font-Awesome/Bootstrap/Remix/etc-Iconset. >> Some Models might have a purpose which can not be mapped to any of those >> icons and need to be custom designed. >> >> >>> 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. >>> >>> That's a violation of the well established MVC pattern of keeping the >> visual part in the view, and the "business model" within the model. >> >> Just my 2 cents >> – 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/7d9fa096-8105-47ab-a778-537294ddccf9n%40googlegroups.com.