fabiocaccamo / django-admin-interface

:superhero: :zap: django's default admin interface with superpowers - customizable themes, popup windows replaced by modals and many other features.
MIT License
1.79k stars 180 forks source link

Enable possibility to use a static file as logo #355

Open BMourguesFieldbox opened 7 months ago

BMourguesFieldbox commented 7 months ago

In the current version, the logo can be user uploaded. However, this means that the app has to handle user uploaded documents and serve them.

When building the admin for business client, the logo will most likely be in static files, and I think it could save some complexity to have the possibility to use a CharField that would point to a static file app/logo.png for example.

Then the template would be with a condition


{% if theme.use_static_logo %}}
    ...
    {% static theme.static_logo_path %}}
 {% else %}
     # The current behaviour
 {% endif %}

Wdyt ?

Upvote & Fund

Fund with Polar

fabiocaccamo commented 7 months ago

@BMourguesFieldbox thank you for this suggestion, it's indeed interesting, I will think more about it.

FraCata00 commented 6 months ago

great solution, instead of CharField, i'll be use a FilePathField

from django docs FilePathField image

BMourguesFieldbox commented 6 months ago

great solution, instead of CharField, i'll be use a FilePathField

from django docs FilePathField image

Good catch ! Didn't think of it, but sure thanks for the suggestion!

FraCata00 commented 6 months ago

great solution, instead of CharField, i'll be use a FilePathField from django docs FilePathField image

Good catch ! Didn't think of it, but sure thanks for the suggestion!

It's better, because you have more control instead of classic CharField

fabiocaccamo commented 6 months ago

@FraCata00 @BMourguesFieldbox to allow users to decide which directory to choose the file from, a conf setting must be added for setting the field path, but this would impact migrations.

FraCata00 commented 6 months ago

@fabiocaccamo the users would do a migration command, cause new field features..

fabiocaccamo commented 6 months ago

@FraCata00 indeed, but that migration will be added to admin_interface app, and when in the future this app will have new migrations there will be some conflicts.

FraCata00 commented 6 months ago

@fabiocaccamo why should there be conflicts?

fabiocaccamo commented 6 months ago

@FraCata00 I try to explain you step by step:

FraCata00 commented 6 months ago

@fabiocaccamo but if you customize the path setting, should not run makemigrations, is a features of FilePathField. We can add a callable to dynamically return the path for the new field, any opinions?

fabiocaccamo commented 6 months ago

@FraCata00 should test it very well:

FraCata00 commented 6 months ago

@fabiocaccamo yessir, after work i'll try it okay? Like the ImageField with a callable upload_to, cannot create every time a new migrations The FilePathField instead a ImageField, accept an existent file in file system, like a poiinter of file system path

FraCata00 commented 6 months ago

@fabiocaccamo I confirm that no new migrations are crreated if the value in settings changed 👍🏻

fabiocaccamo commented 6 months ago

@FraCata00 good news! (should write a couple of test case anyway)

FraCata00 commented 6 months ago

@fabiocaccamo @BMourguesFieldbox I tested personally yesterday evening in my branch to introduce this functionality Just a little bit of testing it better, and i'll do a PR 👍🏻

N.B.: The FilePathField allow (in my case with a custom settings conf), to add a path with some file (just use the match key field to match the most use-case image file (like svg, png, jpg, jpeg) and the django admin provide a html widget select to select the static logo (catched by path)

just add a custom def clean() in Theme model and 2 new fields:

fabiocaccamo commented 6 months ago

@FraCata00 I would add only a new logo_static field, then if both are defined in the backend, the media will have the priority.

FraCata00 commented 6 months ago

@fabiocaccamo oh, maybe is a better solution

FraCata00 commented 6 months ago

@fabiocaccamo sorry for the time *I'm in the office tomorrow morning 😆 ), check PR to solve this issue #378