Yeah, I've tried to create templatetag like this:

@register.simple_tag
def get_module_icon(model, app):
    if app == 'auth':
        if model == 'Groups':
            return '<i class="fas fa-users"></i>'
        elif model == 'Users':
            return '<i class="fas fa-user"></i>'
    elif app == 'core':
        elif model == 'Generations':
            return '<i class="fas fa-layer-group"></i>'
        elif model == 'Product models':
            return '<i class="fas fa-server"></i>'
    elif app == 'bto':
        if model == 'Components':
            return '<i class="fas fa-microchip"></i>'
        elif model == 'Layouts':
            return '<i class="fas fa-drafting-compass"></i>'
        elif model == 'SKU configurations':
            return '<i class="fas fa-gavel"></i>'
        elif model == 'XML component definitions':
            return '<i class="fas fa-cubes"></i>'
    return ''

I don't like this way so much and I thought it would be easier even for 
other potentional developers who would like to use icons so it seemed 
putting it to Meta would be better. However I get mixing HTML to model is 
not good. πŸ™‚
What would be the most clean way to use icons like that?

On Saturday, February 18, 2023 at 8:23:28 PM UTC+1 Arthur Pemberton wrote:

> I too find the idea of hard coded HTML in a Python file to be inelegant, 
> for what it's worth.
>
> Arthur Pemberton
>
> On Sat, 18 Feb 2023 at 08:12, 'Adam Johnson' via Django developers 
> (Contributions to Django itself) <django-d...@googlegroups.com> wrote:
>
>> Putting HTML for the admin in model definitions is a bit too coupled.
>>
>> I think you may be able to add icons already by overriding the admin 
>> template - can you try playing around with that?
>>
>> On Mon, Feb 6, 2023 at 12:07 AM Yeonggwang Yang <immuta...@gmail.com> 
>> wrote:
>>
>>> that sounds good with me
>>>
>>> 2023λ…„ 2μ›” 5일 μΌμš”μΌ μ˜€μ „ 9μ‹œ 36λΆ„ 17초 UTC+9에 Martyλ‹˜μ΄ μž‘μ„±:
>>>
>>>> Hi all,
>>>>
>>>> Recently, it's trend to use icons or emoji before menu items and I like 
>>>> this idea because  IMHO people orient better and more quickly when they 
>>>> see 
>>>> picture.
>>>>
>>>> What about to add this feature to native django? I thought the easiest 
>>>> way would be to add new Meta option to Model. The default Meta icon would 
>>>> be empty string so everything would work like now. If I want to make menu 
>>>> more readable, I just add emoji (πŸ”¨) or html (Awesome font - *<i 
>>>> class="fa-solid fa-hammer"></i>* , Bootstrap icon - *<i class="bi 
>>>> bi-hammer"></i>*, etc.) to Meta icon.
>>>>
>>>> Code example:
>>>>
>>>> *Model:*
>>>> class Hammer(models.Model):
>>>>     ...
>>>>
>>>>     Meta:
>>>>         icon = '<i class="fa-solid fa-hammer"></i>'
>>>>
>>>> *app_list.html template:*
>>>> ...
>>>> <th scope="row">{{model.icon}} {{model.name}}</th>
>>>> ...
>>>>
>>>> Final result:
>>>> [image: admin navbar.png]
>>>>
>>>> Maybe own icon could have even the parent app (AppConfig). And the 
>>>> model icon could be in breadcrumbs.
>>>>
>>>> What do you think about this idea? πŸ™‚
>>>>
>>>> -- 
>>> 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
>>>  
>>> <https://groups.google.com/d/msgid/django-developers/6c859cc5-ea41-4695-9fcf-5cd435310364n%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-develop...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-developers/CAMyDDM1L4rmQ3qomxOqD%2BmugXcsmx7NrOPAh8a53wR9G5q%3D3Gw%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/django-developers/CAMyDDM1L4rmQ3qomxOqD%2BmugXcsmx7NrOPAh8a53wR9G5q%3D3Gw%40mail.gmail.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/1f461742-7fe6-4798-97e9-a8133bd2364bn%40googlegroups.com.
  • Mod... Marty
    • ... Yeonggwang Yang
      • ... 'Adam Johnson' via Django developers (Contributions to Django itself)
        • ... Arthur Pemberton
          • ... Marty
            • ... Mark Niehues
              • ... Jacob Rief
                • ... Marty
                • ... Brice Parent
                • ... Jacob Rief
                • ... Bogdan Barna
                • ... Thibaud Colas

Reply via email to