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/c551140a-ed61-4c24-b41b-7cc228c31972n%40googlegroups.com.