0
我有這樣的形式:如何在django中保存爲「uploaded_to」之前更改上傳的文件?
from django import forms
from manupulators import Replacer
class ContentForm(forms.Form):
csvfile = forms.FileField(label='Select content file')
txtfile = forms.FileField(label='Select changes file file')
def clean(self):
cleaned_data = super(DocumentForm, self).clean()
csvfile = cleaned_data.get("csvdoc")
textfile = cleaned_data.get("txtfile")
if csvfile and textfile:
# Only do something if both fields are valid so far.
"""
here goes nothing
"""
worker = Replacer(csvfile,textfile)
worker.open()
worker.replace()
worker.save() ## how to do this i can alter the replacer to
## return the changed stuff, how will it be saved to
## uploaded_to?
return cleaned_data
的代用品類呼籲高於內部方法修改上傳文本文件,我想只要求他們的替代品後,這些文件保存,即時通訊卡上如何在修改Manupulated內容文件以代替原始內容之後保存它。
這裏是模型:
from django.db import models
class Document(models.Model):
csvfile = models.FileField(upload_to='documents/%Y/%m/%d')
txtfile = models.FileField(upload_to='documents/%Y/%m/%d')