[英]How to export zip in django admin?
I have images fields in my model.我的 model 中有图像字段。 How to I can export to zip from my django admin.
如何从我的 django 管理员导出到 zip。 Here is my code
这是我的代码
from django.db import models
class ModelWithImage(models.Model):
image = models.ImageField(
upload_to='images',
)
Admin行政
from django.contrib import admin
from .models import ModelWithImage
admin.site.register(ModelWithImage)
Something like this is used to create zipfile for content in files (path) in filenames
.像这样的东西用于为
filenames
中的文件(路径)中的内容创建 zipfile。
response = HttpResponse(content_type='application/zip')
zip_file = zipfile.ZipFile(response, 'w')
for filename in filenames:
zip_file.write(filename)
response['Content-Disposition'] = 'attachment; filename={}'.format(zipfile_name)
return response
This code is taken from here , you may have a look for better understanding.这段代码取自这里,你可以看看更好的理解。 Although I think above code should solve your problem.
尽管我认为上面的代码应该可以解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.