Uploading multiple images in Django admin

人走茶凉 提交于 2019-11-28 18:28:05

You can extend the Admin interface pretty easily using Javascript. There's a good article on doing exactly what you want with a bit of jQuery magic.

You would just have to throw all of his code into one Javascript file and then include the following in your admin.py:

class Photo(admin.ModelAdmin):
    class Media:
        js = ('jquery.js', 'inlines.js',)

Looking at his source, you would also have to dynamically add the link to add more inlines using Javascript, but that's pretty easy to do:

$(document).ready(function(){
    // Note the name passed in is the model's name, all lower case
    $('div.last-related').after('<div><a class="add" href="#" onclick="return add_inline_form(\'photos\')">');
});

You probably need to do some styling to make it all look right, but that should get you started in the right direction.

Also, since you're in inline land, check out the inline sort snippet.

photologue is a feature-rich photo app for django. it e.g. lets you upload galleries as zip files (which in a sense means uploading multiple files at once), automatically creates thumbnails of different custom sizes and can apply effects to images. I used it once on one project and the integration wasn't too hard.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!