I have a standard Django Admin page that is used to upload multiple files. I wish to do the following:
I only have a very basic admin page now. Can anyone point me to the right direction in where to start with? Please point me exactly which file i need to modified as i am still unfamiliar with django.
Just a brief direction will be appreciated. Thank you.
I didn't test these code, but I can just direct you where to start. I would suggest you to write the code of unzipping at the model's save function. This is the easiest way but not the best. Django admin can handle multiple form as customizing django admin.
I hope your models are somewhat like these
from django.db import models
from django.core.files.storage import FileSystemStorage
fs = FileSystemStorage(location="/var/www/yoursite/private/")
class SetOfFiles(models.Model):
name = models.CharField('set name'), max_length=225, null=False, blank=False)
class File(models.Model):
set = models.ForeignKey(SetOfFiles, verbose_name=_('set'))
file = models.FileField(storage=fs)
def save(self, *args, **kwargs):
if not self.id:
... unzip your file ...
... encrypt your file if necessary ...
super(File, self).save(*args, **kwargs)
Create admin.py in the related app customizing your admin to handle multiple insertion:
from django.contrib import admin
class FileInline(admin.TabularInline):
model = File
class SetOfFilesAdmin(admin.ModelAdmin):
list_display = ('name',)
inlines = [FileInline]
admin.site.register(SetOfFiles, SetOfFilesAdmin)
Here is also Unzip a .zip file uploaded with FileBrowser code but it could be a little bit complicated due to using FileBrowser app. You can unzip file just using the zipfile python module. Also you may use PyCrypto at AES encryption.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With