Skip to content

A model field to store a file size, whose edition and display shows units (KB, MB, ...)

License

Notifications You must be signed in to change notification settings

cedadev/django-sizefield

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-sizefield is a file size field, stored as BigInteger and rendered with units in Bytes (KB, MB, KiB, Mib, ...)

https://travis-ci.org/leplatrem/django-sizefield.png https://coveralls.io/repos/leplatrem/django-sizefield/badge.png

INSTALL

pip install django-sizefield

USAGE

Model field

class Data(models.Model):
    path = models.FilePathField()
    size = FileSizeField()

The model form will have a TextInput, which renders the value with units, and accepts values with or without units.

size = FileSizeField(is_binary=False)

It is possible to have fields with decimal size. In this instance, a value of 1KB would be parsed as 1000 bytes.

Template filter

It adds units to any number value:

{% load sizefieldtags %}

{{ value|filesize }}

will render 12.3KB (for example)

To explicitly declare the type of formatting desired, use:

{% custom_filesize 1024 binary=True ambiguous_suffix=False %}

will render as 1KiB

Settings

By default, 1KB and 1KiB will both parse to 1024 bytes.

SIZEFIELD_IS_BINARY = False
SIZEFIELD_AMBIGUOUS_SUFFIX = False
SIZEFIELD_ASSUME_BINARY = False

With settings similar to the above, the default will assume that 1KB represents 1000 bytes. Formatting from byte values will also follow this rule.

AUTHORS

LICENSE

  • Lesser GNU Public License

About

A model field to store a file size, whose edition and display shows units (KB, MB, ...)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%