jowilf / starlette-admin

Fast, beautiful and extensible administrative interface framework for Starlette & FastApi applications
https://jowilf.github.io/starlette-admin/
MIT License
630 stars 59 forks source link

Enhancement: ImageFromUrlField #281

Open sglebs opened 1 year ago

sglebs commented 1 year ago

https://jowilf.github.io/starlette-admin/api/fields/#starlette_admin.fields.ImageField lists UrlField (makes URL clickable) and lists ImageField (based on files). How about an Image Field that contains an image URL instead of the image bytes? Maybe ImageField could be changed so that it does not assume it is a file? (I tried it, on the column that has a URL, and it did not work).

Do we need to implement "ImageFromUrlField"?

Upvote & Fund

Fund with Polar

jowilf commented 1 year ago

You can create a custom field that inherit UrlField and customize the list & detail rendering. feel free to submit a PR

sglebs commented 1 year ago

These template files... I just need to create a directory off the top of my project and put the html there? Is there a "search path" mechanism? Like "first I try to find it in the project where I am running, then in starlet-admin's dir, then...".

I mean, if I create a /displays in my project and save my own customized url.html there, then the URLField will automatically render my way?

    display_template: str = "displays/url.html"

It turns out the URL I will have to embed may be an image or an audio or a video, so I will probably need to implement a MultimediaFromUrlField and put the logic in to generate the best HTML markup.

jowilf commented 1 year ago

By default, starlette-admin will search in your templates directory. You can customize it by providing a custom templates_dir https://jowilf.github.io/starlette-admin/tutorial/configurations/admin/