本文整理匯總了Python中models.Document.filepath方法的典型用法代碼示例。如果您正苦於以下問題:Python Document.filepath方法的具體用法?Python Document.filepath怎麽用?Python Document.filepath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Document
的用法示例。
在下文中一共展示了Document.filepath方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: save_document
# 需要導入模塊: from models import Document [as 別名]
# 或者: from models.Document import filepath [as 別名]
def save_document(request_file, content_subdir, related_obj, ashash = True):
uploadedfile = UploadedFile(request_file)
file_content = uploadedfile.read()
doc_obj = Document()
doc_obj.filehash = md5(file_content).hexdigest()
doc_obj.urlencfilename = quote(uploadedfile.name)
doc_obj.filename = uploadedfile.name
doc_obj.content_type = uploadedfile.file.content_type
if ashash:
doc_obj.filepath = settings.BASE_DIR + content_subdir + doc_obj.filehash
else:
doc_obj.filepath = settings.BASE_DIR + content_subdir + doc_obj.filename
if related_obj.__class__.__name__.lower() == "queryset":
if len(related_obj) == 1:
setattr(doc_obj, related_obj[0].__class__.__name__.lower(), related_obj[0])
else:
print "ERROR: The queryset object had %s elements to it" % str(len(related_obj))
else:
setattr(doc_obj, related_obj.__class__.__name__.lower(), related_obj)
doc_obj.save()
wfile = open(doc_obj.filepath, "w")
wfile.write(file_content)
wfile.close()