如何在django中保存为“uploaded_to”之前更改上传的文件?

问题描述:

我有这样的形式:如何在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') 

原来我能得到的意见的路径,

if request.method == 'POST': 
     form = ContentForm(request.blah,request.blah) 
     if form.is_valid(): 
      docs = Document(csvdoc = ...,txtfile = ..., 
        app_user=...,) 
      docs.save() 
      pathone = docs.csvdoc.path 
      pathtwo = docs.txtfile.path # all done