Skip to content

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

License

Notifications You must be signed in to change notification settings

thekitaev/django-zipbulkupload

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages