我想知道是否可以在Django模型中存储数组?
我问这个是因为我需要在一个字段中存储一个int数组(例如[1,2,3]),然后能够搜索一个特定的数组并获得它的匹配或它的可能组合.
我想将这些数组存储为字段中的字符串然后,当我需要搜索某些内容时,将值(通过过滤其他模型获得)与'[',']'和','连接,然后使用对象过滤器生成字符串.问题是我必须生成每个可能的组合,然后逐个过滤,直到我得到一个匹配,我相信这可能是低效的.
所以,我希望你能给我一些我可以尝试的想法.
我不是必须要求代码,任何有关如何实现这一点的想法都会很好.
我想知道是否有一种方法可以将静态图像文件用作ImageField的默认值?
我之所以这样问是因为,如果首先编写这样的内容,是因为我无法将媒体文件夹上传到我的github存储库中,因为我将用户上传的内容存储在其中,并且默认文件始终是相同的,所以我想从静态提供默认值,但用户从媒体目录上载。
如果使用此:
image = models.ImageField(upload_to=/upload/folder/, default=/img/default.jpg, blank=True, null=True)
Run Code Online (Sandbox Code Playgroud)
它将尝试从媒体目录加载默认图像。
是否可以在django中将多个pdf与weasyprint合并?
我有这样的事情:
def verpdf(request, pk):
odet = get_object_or_404(Note, pk = pk)
template = get_template('pdfnot.html')
template1 = get_template('pdfnot2.html')
p1 = template.render({'odet': odet}).encode(encoding="ISO-8859-1")
p2 = template1.render({'note':odet}).encode(encoding="ISO-8859-1")
pdf1 = HTML(string=p1).render()
pdf2 = HTML(string=p2).render()
all_pages = [po for po in pdf1.pages for doc in pdf2.pages]
pdf_file = pdf1.copy(all_pages).write_pdf()
http_response = HttpResponse(pdf_file, content_type='application/pdf')
http_response['Content-Disposition'] = 'filename="report.pdf"'
return http_response
Run Code Online (Sandbox Code Playgroud)
但是我无法加入这两个文件,总是只输出第一个模板,是否有可能将两个文件合并为一个pdf?你能帮助我吗?谢谢。