A Django app for the uploading of large files from the django admin site.
Project description
django-admin-resumable2
django-admin-resumable2 is a django app to allow you to upload large files from within the django admin site.
Screenshot
Installation
* pip install django-admin-resumable2
* Add ``admin_resumable2`` to your ``INSTALLED_APPS``
* Add ``path('', include('admin_resumable2.urls')),`` to your urls.py
* Add a model field eg: ``from admin_resumable2.fields import ModelAdminResumableFileField``
::
class Foo(models.Model):
title = models.CharField(max_length=200)
file = ModelAdminResumableFileField(upload_to='foo/')
# use below code to change path of resumable
def save(self, force_insert=None, force_update=None, using=None, update_fields=None):
old_path = self.file.path # Get the current old path
file_name = os.path.basename(old_path) # get file name
upload_to_method = Foo._meta.get_field('file').orig_upload_to # Get the original upload to path
if type(upload_to_method) == str:
orig_upload_to = upload_to_method + file_name
else:
orig_upload_to = upload_to_method(self, file_name)
new_path = os.path.join(settings.MEDIA_ROOT, orig_upload_to) # Create the original path
directory = os.path.dirname(new_path)
os.makedirs(directory, exist_ok=True)
if new_path != old_path:
while True:
file_name, file_extension = os.path.splitext(new_path)
random_value = ''.join(random.choices(string.ascii_lowercase + string.digits, k=7))
new_path = file_name + '_' + random_value + file_extension
if not os.path.exists(new_path):
orig_upload_to = new_path.replace(str(settings.MEDIA_ROOT), '')
break
shutil.move(old_path, new_path)
self.file.name = orig_upload_to
return super().save(force_insert, force_update, using, update_fields)
Optionally:
* Set ``ADMIN_RESUMABLE_SUBDIR``, default is ``'admin_uploaded'``
* Set ``ADMIN_RESUMABLE_CHUNKSIZE``, default is ``"1*1024*1024*5"``
* Set ``ADMIN_RESUMABLE_STORAGE``, default is ``'django.core.files.storage.FileSystemStorage'``
Compatibility
{py37, py38, py310}-django{4.* above}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-admin-resumable2-0.1.tar.gz.
File metadata
- Download URL: django-admin-resumable2-0.1.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
030be540afc75aa9a32b863f2d87a747da7b967a0ca237397a04483a007cbc9d
|
|
| MD5 |
2dac014cb5bec7259a8282a814a24ef6
|
|
| BLAKE2b-256 |
42a4dce1779ec3b33b9fa168b99fc7338ef7a0e5ffec737520cbe907c4680233
|
File details
Details for the file django_admin_resumable2-0.1-py3-none-any.whl.
File metadata
- Download URL: django_admin_resumable2-0.1-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8550ac45130ff48ec71f851e94e84e5d691d64415520917970926de867907b24
|
|
| MD5 |
3fb363baccd126ad32bfb475c3908fe1
|
|
| BLAKE2b-256 |
75c48671b05e6a1040cfc922ce530670d4247097b52e185ddee195463165108a
|