在Django管理员中上传多个图像 [英] Uploading multiple images in Django admin

查看:136
本文介绍了在Django管理员中上传多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为客户建立投资组合网站,而我在一个小区域遇到困难。我想能够为每个投资组合项目内联上传多个图像(不同数量),我看不到一个明显的方法。

I'm currently building a portfolio site for a client, and I'm having trouble with one small area. I want to be able to upload multiple images (varying number) inline for each portfolio item, and I can't see an obvious way to do it.

最多的用户友好的方式我可以看到将是一个带有JavaScript控件的文件上传表单,允许用户根据需要添加更多的字段。有谁有这样的问题有任何经验吗?确实,有没有任何自定义的库可以解决我的问题?

The most user-friendly way I can see would be a file upload form with a JavaScript control that allows the user to add more fields as required. Has anybody had any experience with an issue like this? Indeed, are there any custom libraries out there that would solve my problem?

我以前没有调用修改管理工具,所以我不是真的知道从哪里开始。

I've had little call for modifying the admin tool before now, so I don't really know where to start.

感谢任何可以散发光芒的人。

Thank you to anybody who can shed some light.

推荐答案

您可以使用Javascript轻松扩展Admin界面。有一个好文章完成你想要的一些jQuery魔术。

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.

你只需要把他的所有代码放入一个Javascript文件,然后在你的admin.py:

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',)

看他的来源,你也会必须动态添加链接以使用Javascript添加更多内联,但这很容易做到:

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.

另外,由于您在 inline land,请查看内联排序片段

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

这篇关于在Django管理员中上传多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆