[Django] #30843: New argument for FileField and descendants: size_field

9 views
Skip to first unread message

Django

unread,
Oct 6, 2019, 4:57:50 PM10/6/19
to django-...@googlegroups.com
#30843: New argument for FileField and descendants: size_field
-------------------------------------------+------------------------
Reporter: Maksim Iakovlev | Owner: nobody
Type: New feature | Status: new
Component: Uncategorized | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
`size_field` must work same as `ImageField.width_field`, but for file size
in bytes. It may be helpful in systems which use remote storages. For
example, S3 storage from django-storages makes HEAD request for every
`file.size` call. It's painful sometimes.

--
Ticket URL: <https://code.djangoproject.com/ticket/30843>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 7, 2019, 2:38:02 AM10/7/19
to django-...@googlegroups.com
#30843: New argument for FileField and descendants: size_field.
-------------------------------------+-------------------------------------

Reporter: Maksim Iakovlev | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => closed
* resolution: => wontfix
* component: Uncategorized => Database layer (models, ORM)


Comment:

Thanks for this report, however this looks like sth that should be fixed
in `django-storages`. I don't see many use cases for this feature. You can
always add a `@cached_property` to your model to avoid multiple calls of
`FileField.size`, e.g.
{{{
@cached_property
def file_size(self):
return self.file.size
}}}
You can also create a custom field:
{{{
class MyFileField(FileField):
@cached_property
def custom_size_attribute(self):
return self.size
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30843#comment:1>

Reply all
Reply to author
Forward
0 new messages