It would be really awesome if I could add this jQuery file uploader to my Django admin panel, but I'm new to Django and I'm not really sure where to start. Could someone give me some ideas, and point me in the right direction here?
-
Had you tried django-directupload?ilvar– ilvar2012-05-11 06:02:36 +00:00Commented May 11, 2012 at 6:02
-
That does look interesting. Have you used it before? I'm having having trouble getting it to workHighLife– HighLife2012-05-11 07:57:42 +00:00Commented May 11, 2012 at 7:57
-
Nope :) What problems do you have?ilvar– ilvar2012-05-11 19:42:03 +00:00Commented May 11, 2012 at 19:42
-
stackoverflow.com/questions/10555433/…HighLife– HighLife2012-05-11 20:57:47 +00:00Commented May 11, 2012 at 20:57
-
Why don't you use github.com/sentido/django-ajax-upload-widgetPlamen Nikolov– Plamen Nikolov2012-09-18 14:27:32 +00:00Commented Sep 18, 2012 at 14:27
Add a comment
|
2 Answers
You can install package django-admin-multiupload, which is added into the django admin a form based on jQuery File Upload, by next command:
pip install git+git://github.com/gkuhn1/django-admin-multiupload.git
Or just clone into your project from https://github.com/gkuhn1/django-admin-multiupload.git Example of usage:
from django.contrib import admin
from django.shortcuts import get_object_or_404
from gallery.models import Gallery, Image
from multiupload.admin import MultiUploadAdmin
class ImageInlineAdmin(admin.TabularInline):
model = Image
class GalleryMultiuploadMixing(object):
def process_uploaded_file(self, uploaded, gallery, request):
if gallery:
image = gallery.images.create(file=uploaded)
else:
image = Image.objects.create(file=uploaded, gallery=None)
return {
'url': image.file.url,
'thumbnail_url': image.file.url,
'id': image.id,
'name': image.filename
}
class GalleryAdmin(GalleryMultiuploadMixing, MultiUploadAdmin):
inlines = [ImageInlineAdmin,]
multiupload_form = True
multiupload_list = False
def delete_file(self, pk, request):
'''
Delete an image.
'''
obj = get_object_or_404(Image, pk=pk)
return obj.delete()
class ImageAdmin(GalleryMultiuploadMixing, MultiUploadAdmin):
multiupload_form = False
multiupload_list = True
admin.site.register(Gallery, GalleryAdmin)
admin.site.register(Image, ImageAdmin)
Where Gallery and Image models are:
from django.db import models
# Create your models here.
class Gallery(models.Model):
class Meta:
verbose_name_plural = 'Galleries'
title = models.CharField('Title', max_length=20)
def __str__(self):
return self.title
class Image(models.Model):
file = models.FileField('File', upload_to='images/')
gallery = models.ForeignKey('Gallery', related_name='images', blank=True, null=True)
def __str__(self):
return self.filename
@property
def filename(self):
return self.file.name.rsplit('/', 1)[-1]
1 Comment
David Wheaton
django-admin-multiupload worked for me for basic admin support of multiple file upload using the jquery file upload plugin.