Python 如何在django中更改上载的文件,然后将其保存到";上传到;?

Python 如何在django中更改上载的文件,然后将其保存到";上传到;?,python,django-models,django-forms,Python,Django Models,Django Forms,我有一张这样的表格: 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):

我有一张这样的表格:

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
Replacer类有上面调用的内部方法,可以修改上传的文本文件,我只想在调用Replacer后保存这些文件,我一直在研究如何在修改手动内容文件而不是原始内容后保存这些文件

模型如下:

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