在django中选择多个文件,单个文件夹 [英] select multiple files in django with single filefield

查看:255
本文介绍了在django中选择多个文件,单个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在django中的单个文件中选择多个文件?我想在django admin中的一个文件中选择不同的文件格式。

How can I select multiple files in a single fileField in django? I want to select different file formats in a single filefiled in django admin.

**models.py**
 class FileModel(models.Model):
    name = models.CharField(max_length=100)
    file_upload = models.FileField(upload_to=settings=PATH)

**admin.py**
 admin.site.register(FileModel,FileAdmin);

在管理员中我想自定义文件字段以选择多个文件存储在给定的路径?你能帮我吗?

In the admin I want to customize the file field to select multiple files to store in given path? Could you please help me?

推荐答案

你不能吗? FileField不是为此设计的。

You can't? The FileField was not designed for that purpose.

您必须定义自己的字段(可能从FileField扩展),可以打开内部数据(多个文件的路径)和将它们存储在数据库中并解开它们。

You would have to define your own field (possibly extended from FileField) that pickles the internal data (paths to multiple files) and stores them in the database and unpickles them back.

当然,我根本看不出有理由这样做,当你可以简单地定义一个很多的关系或者甚至是新的文件列表模型和现有文件模型之间的许多关系。然后,您可以将一个内联管理员处理程序附加到上传者模型,您可以轻松地添加多个文件。

Of course, I don't see a reason to do this at all, when you can simply define one to many relationship or even many to many relationship between a new filelist model and existing filemodel. Then you could make an inline admin handler attached to the uploader model and you can add multiple files easily that way.

请参阅内联管理模型

这篇关于在django中选择多个文件,单个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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