django-cms / django-filer

File and Image Management Application for django
https://django-filer.readthedocs.io/
Other
1.76k stars 577 forks source link

Request: Extend Folders similar to extending images #1406

Closed toddstowell closed 10 months ago

toddstowell commented 1 year ago

Are there plans to allow for extending the folder model similar to the file model? We have some additional data values we'd like to attribute to a folder but do so without forking.

marksweb commented 1 year ago

What kind of data? If it's something that would be useful to others maybe you could raise a PR for it?

toddstowell commented 1 year ago

@marksweb we reuse folders for slideshows on a media site. We're looking to add a formal title and description to each folder that would be be surfaced on the front end for our users. The slideshow is made of images from within the folder.

jrief commented 1 year ago

Are there plans to allow for extending the folder model similar to the file model? We have some additional data values we'd like to attribute to a folder but do so without forking.

This has never been discussed yet. Do you have some use-cases to share? Folders in my opinion do not have much potential for extension, but I might be wrong on this.

Anyway, I'd like to add a JSONField to each File and Folder model so that one can store arbitrary data for its own use-case, without having to migrate existing models. The latter is really painful. By using https://github.com/jrief/django-entangled one can then make those extra fields editable, in a similar way he would do with model fields.

yml commented 1 year ago

I think this can be done in a backward compatible way like it was done few years ago for settings.FILER_IMAGE_MODEL . The idea is to use Django Swappable model interface.

One of the reason I do not love the idea of JsonField is that it is limited compare to the option to fully swap the model with a custom one.

The change for the swappable Image model was done in the 2 PRs below:

jrief commented 1 year ago

@yml I actually want to ditch the ImageModel in favor of a proxy model. Those models can be swapped easily.

What kind of use-case do you have where you need a materialized Django model for images?

yml commented 1 year ago

Hey, @jrief! I was wondering if you could provide a detailed description of your thoughts on removing ImageModel. My understanding is that the main objective is to eliminate the reliance on django-polymorphic. The challenge lies in removing the swappable ImageModel since currently, as far as I know, you can't swap the File model. Perhaps we could have a separate discussion about this change to avoid diverting attention from the ongoing discussion about swapping the Folder model.

Could you share some specific use-cases where having a materialized Django model for images is necessary?

In essence, we have numerous customized behaviors, attributes, and foreign keys associated with the modified Image. By custom behaviors, I mean functionalities like a custom _generate_thumbnails(..) to use a thumbnailer like thumbor instead of easy-thumbnail. Custom attributes refer to database columns that are used to build efficient indices and facilitate changes in ordering of Image queryset or foreign key relationships with other content in the database..

jrief commented 1 year ago

@yml Yes, there is a detailed proposal, please see #1348

The intention is to use one JSON field and proxy models. This allows us to add custom behavior in a very simple way.

I always found it very painful having to work with swappable models. As far as I remember, Django introduced some helpers for this. Do you know of any project using that?

In Django-Shop I introduced foreign keys which materialize during the bootstrapping phase. This was quite an elegant solution which avoided swappable models.

stale[bot] commented 11 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 10 months ago

This will now be closed due to inactivity, but feel free to reopen it.

jrief commented 10 months ago

@toddstowell I'm currently rewriting django-filer. The new model for folder contains a JSONField which can be used to store arbitrary data. So this might be a good fit for you.