#33993: Allow instance to be passed into the FileField storage callable param
-------------------------------------+-------------------------------------
Reporter: Viicos | Owner: nobody
Type: New feature | Status: new
Component: File | Version: dev
uploads/storage |
Severity: Normal | Resolution:
Keywords: callable, storage, | Triage Stage:
filefield | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Viicos:
Old description:
> 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.
New description:
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:
{{{
#!python
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#comment:1>
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/01070183194d65a7-91edeadb-f90a-453d-88eb-218c49a3cf4d-000000%40eu-central-1.amazonses.com.