Giter VIP home page Giter VIP logo

django-zipbulkupload's Introduction

django-zipbulkupload

Abstract model for easily creating related instances by uploading ZIP-archive to a model field.

How to use

First install package with

pip install git+git://github.com/thekitaev/django-zipbulkupload

Or just download it and copy to project root.

Add zipbulkupload to INSTALLED_APPS.

In models.py inherit parent model from ZipBulkUploadModel. Add FromZipFileField with to_model (app.Model) and to_field attributes. If you need to limit file formats, you can add exts with a list or tuple of .ext's.

Default zip field name is bulk_upload but you can rename it at BUMeta.bulkupload_field.

Add a second model with a ForeignKey to first one. Add a target field for files. Should work for any subclasses or FileField and ImageField.

Example:

from django.db import models
from zipbulkupload.models import ZipBulkUploadModel
from zipbulkupload.fields import FromZipFileField


class Parent(ZipBulkUploadModel):
    name = models.CharField('name', max_length=50)
    bulk_upload = FromZipFileField(to_model='main.Child', to_field='image', exts=('.jpg', '.png'))
    # other things


class Child(models.Model):
    parent = models.ForeignKey('Parent')
    image = models.FileField()
    # and so on

Then makemigrations and migrate with manage.py.

Now pack your files into a ZIP-archive. Create an instance and upload an archive to FromZipFileField. Voilà!

TODO

  • Change FromZipFileField's to_model format to ForeignKey's one
  • Tests
  • Exceptions raising for wrong parameters
  • Several fields for one model
  • Filter in-archive system files (done partially)
  • Move functionality from model to field (maybe)

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.