Code Monkey home page Code Monkey logo

django-uploader-drag_drop's Introduction

Django Uploader

What it does

Django Uploader uses jQuery file upload to allow drag-and-drop file upload of any file type in the Django Admin. Third-party applications to write handlers for specific file types, and register them with Django Uploader. When a file of that type is uploaded, it passes the information to the handler so that it can make a new record with that file.

Installation

  1. Installation is easy using pip:

    pip install django-uploader

  2. Add uploader to your INSTALLED_APPS setting.

  3. Add the uploader's urls:

    url(r'^upload/', include('uploader.urls')),

  4. Write one or more upload handlers.

  5. Go to /admin/uploader/upload/ to start uploading.

Writing an upload handler

Note

An upload handler does not have to exist within the application for which it creates records. It must simply be within an application that is imported so the handler can be discovered.

An upload handler assigns one or more MIME types to a function. There should only be one handler for a given MIME type, although Uploader does allow some overlap using '*'. For example, you can have one handler that handles image/tiff and another that handles image/* and yet another that handles */*. The image/tiff handler would get any .tiff images, the image/* would get any other type of image and the */* handler would get any other type of file.

To start, create a file named upload.py in your application. This file can contain several different handlers. When the Uploader application is first loaded, it attempts to import this file from every installed application.

A basic handler looks like this:

from uploader.registration import upload_handlers

def photo_handler(obj):
    """
    Handle the creation of a SimpleModel record from an uploaded image.
    """
    from .models import SimpleModel

    new_item = SimpleModel.objects.create(
        name=obj.filename,
        slug=obj.filename_slug,
        description='',
        file=obj.file_contents
    )

    return new_item
photo_handler.thumbnail_attribute = 'thumb'

upload_handlers.register(['image/jpeg', 'image/png'], photo_handler)

django-uploader-drag_drop's People

Contributors

coordt avatar cnobile2012 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.