0

我有这样的表格:

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 类具有上面调用的内部方法来修改上传的文本文件,我只想在对它们调用替换器后保存这些文件,我坚持在修改后如何保存操纵的内容文件代替原始内容.

这是模型:

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')
4

1 回答 1

0

原来我可以在视图中获得路径,

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
于 2013-07-02T19:27:17.077 回答