Skip to main content

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

screenshot_1 screenshot_2 screenshot_3 screenshot_4 screenshot_5

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

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

resumable2-0.1.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

resumable2-0.1-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file resumable2-0.1.tar.gz.

File metadata

  • Download URL: resumable2-0.1.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.5

File hashes

Hashes for resumable2-0.1.tar.gz
Algorithm Hash digest
SHA256 6f6add4162590f4ebe4e96a09353344746b5e8d7e8275ddcd71b2d0f10aa87a1
MD5 bb85ef895a565953a1dcc7a29f1418a1
BLAKE2b-256 956f1c93ff79485e5b72fd87b86c87a40429e8486aa756b936d3f45033c44adb

See more details on using hashes here.

File details

Details for the file resumable2-0.1-py3-none-any.whl.

File metadata

  • Download URL: resumable2-0.1-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.5

File hashes

Hashes for resumable2-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7217a546414877ea9a2aa8454dc5517482a19bf706bb9ff1fde642b0d23b903b
MD5 b7472f6bf2e16404428dbc064fbb2e41
BLAKE2b-256 fe61e647f63ffc963bb1ad7c71a0e75ba3a80434bb92feaa7544ddf6df00eb4f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page