Opened 2 years ago

Last modified 2 years ago

#33993 closed New feature

Allow instance to be passed into the FileField storage callable param — at Initial Version

Reported by: Viicos Owned by: nobody
Component: File uploads/storage Version: dev
Severity: Normal Keywords: callable, storage, filefield
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

A while ago #28184 introduced the ability to use callables as the storage parameter of the FileField.

Someone even requested the ability to have the instance passed into the callable: https://github.com/django/django/pull/8477/files#r226555624

But I believe @miigotu misinterpreted it and was thinking about a Storage instance.

What could be great is the ability to pass the instance (and maybe the filename too) similar to upload_to

Example:

def get_storage(instance, filename):
    if instance.is_private:
        return PrivateStorage()
    else:
        ...

This could allow the user to use a specific storage depending on the instance being saved.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top