--
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-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/6c859cc5-ea41-4695-9fcf-5cd435310364n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM1L4rmQ3qomxOqD%2BmugXcsmx7NrOPAh8a53wR9G5q%3D3Gw%40mail.gmail.com.
If we are talking only about icons in Django Admin: Wagtail (a CMS based on Django) solves it for their custom Admin Views in a similar way to your proposed Meta attribute [0].
The analog solution for django admin would be, that the ModelAdmin gets an 'icon' attribute, which does not contain the whole html-snippet, but instead only the icon specific class name:
For Example:from django.contrib import admin
from .models import Author
@admin.register(Author)
class AuthorAdmin(admin.ModelAdmin):
icon = 'fa-user'
That would be a nicer solution in my point of view, especially I find this level of coupling acceptable.
Cheers,
Mark
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/1f461742-7fe6-4798-97e9-a8133bd2364bn%40googlegroups.com.
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:
--
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-develop...@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.
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.