Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/agconti/django-unique-upload
A django utility that creates unique file names for uploaded files via uuids.
https://github.com/agconti/django-unique-upload
Last synced: about 2 months ago
JSON representation
A django utility that creates unique file names for uploaded files via uuids.
- Host: GitHub
- URL: https://github.com/agconti/django-unique-upload
- Owner: agconti
- License: mit
- Created: 2016-02-10T17:34:19.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-02-11T02:28:39.000Z (over 8 years ago)
- Last Synced: 2024-07-20T15:12:18.691Z (2 months ago)
- Language: Python
- Size: 16.6 KB
- Stars: 17
- Watchers: 5
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# django-unique-upload
[![Build Status](https://travis-ci.org/agconti/django-unique-upload.svg?branch=master)](https://travis-ci.org/agconti/django-unique-upload)A django utility that creates unique file names for uploaded files via uuids.
## Why
This eliminates the need to check if the a file already exists with the same name. Checking incurs overhead. Removing the need to check boosts performance. Popular pacakges like django storages don't check if a file already exists with the same name by default. They instead overwrite the file. Using unique file names ensures that no file is over written.## Install
```bash
pip install django-unique-upload
```## Usage
Simply use the `unique_upload` function as value for a model's `FileField` or `ImageField` `upload_to` argument:
```python
from __future__ import unicode_literalsfrom django.db import models
from django.utils.encoding import python_2_unicode_compatible
from unique_upload import unique_upload@python_2_unicode_compatible
class MyModel(modles.Model):
image = models.ImageField(upload_to=unique_upload)
file = models.FileField(upload_to=unique_upload)
```
Now if we give save `MyModel` with two new files, `cool-image.jpg` and `really-important.pdf`, Django will save the files to S3 with the values: `3fce8b21-5b0d-4f27-9d99-2bb202f211c7.jpg` and `50a44439-843e-4049-949d-b54cfcddff19.pdf`.## Tests
Run the devepment tests with:
```bash
python -m unittest discover test
```