ImperialCollegeLondon / django-drf-filepond

A Django app providing a server implemention for the Filepond file upload library
BSD 3-Clause "New" or "Revised" License
105 stars 40 forks source link

StoredUpload should be hotswappable #45

Closed brianedelman closed 3 years ago

brianedelman commented 4 years ago

Currently working on a project where I want StoredUpload to have some extra data attached to it and there currently isn't a way to define my own model for the library to use. Is that something on the roadmap/useful for others?

jcohen02 commented 4 years ago

Thanks for raising this @brianedelman, this would certainly be a useful enhancement. Can you provide a little more detail as to what you had in mind in terms of the functionality you'd be looking for?

If you were to extend the StoredUpload model class with your custom model parameters and then have a new option in the settings where you could set the name of the stored upload class, say, DJANGO_DRF_FILEPOND_STORED_UPLOAD_CLASS, would this solve the issue? The store_upload function in api.py could then perhaps be extended to include an optional additional_params parameter where you'd pass in a dict containing the additional data to store in your custom StoredUpload object.

Alternatively, would you be looking for something more flexible where you can specify the upload model when you save the upload? I guess this could be handled by specifying the upload model name as a parameter to store_upload but then lookups would become very challenging so this probably needs more thought.

Yet another option would be that you create a separate model for your additional data that extends some placeholder model class. We then have an optional foreign key in the StoredUpload model where we can attach a reference to an additional model data class. You could then pass in a pre-created object to store_upload that contains your additional data and have this linked to the StoredUpload object that is saved.

Just a few thoughts on how this might be addressed. Let me know if you have any thoughts on what might work best for your use case or if you had something different in mind. Also happy to receive suggestions on what approach might be best from the general architecture perspective of the library.

I can look at implementing this, otherwise if you want to have a go and open a PR, that's also fine.

jcohen02 commented 3 years ago

This issue has come up again in #62 and I've opened a new issue (#63) to work on this. Thanks @brianedelman for raising this initially and for your work looking at implementing this. I think I can see a simplified approach to addressing this initially (although I may well be missing something!) so will have a go.

I'm going to close this issue and move discussion to on this feature to #63. Do feel free to contribute or provide feedback on any implementation if you're still working with this and would find the feature helpful.

jcohen02 commented 3 years ago

Discussion on this feature is continuing in #63.