#33993: Allow instance to be passed into the FileField storage callable param
-------------------------------------+-------------------------------------
Reporter: Viicos | Owner: nobody
Type: New | Status: new
feature |
Component: File | Version: dev
uploads/storage | Keywords: callable, storage,
Severity: Normal | filefield
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
A while ago [https://code.djangoproject.com/ticket/28184/ #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
[https://docs.djangoproject.com/en/4.1/ref/models/fields/#django.db.models.FileField.upload_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.
--
Ticket URL: <https://code.djangoproject.com/ticket/33993>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070183194aef6c-ecda5c15-e9e6-4869-b7ff-dc6415bfc047-000000%40eu-central-1.amazonses.com.