Opened 5 years ago

Closed 5 years ago

#30843 closed New feature (wontfix)

New argument for FileField and descendants: size_field.

Reported by: Maksim Iakovlev Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (1)

comment:1 by Mariusz Felisiak, 5 years ago

Component: UncategorizedDatabase layer (models, ORM)
Resolution: wontfix
Status: newclosed
Summary: New argument for FileField and descendants: size_fieldNew argument for FileField and descendants: size_field.

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
Note: See TracTickets for help on using tickets.
Back to Top