'FileField'没有属性'save'

时间:2014-04-10 04:04:51

标签: python django soap suds mezzanine

我正在开发一个Mezzanine模型,只想发送一个SOAP请求,并使用models.py中的代码将该响应保存为Django FileField中的文件。

我在https://docs.djangoproject.com/en/1.6/ref/models/fields/#django.db.models.FileField

看到了Django文档

我已阅读此内容 - Django - how to create a file and save it to a model's FileField?

但是,我仍然得到追溯......

  File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 271, in get_model
    self._populate()
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 75, in _populate
    self.load_app(app_name, True)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 99, in load_app
    models = import_module('%s.models' % app_name)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/home/docker/hydroshare/timeSeriesApp/models.py", line 18, in <module>
    class TimeSeries(Page, RichText, AbstractResource, models.Model):
  File "/home/docker/hydroshare/timeSeriesApp/models.py", line 37, in TimeSeries
    resource_file.save('My File', ContentFile('A string with the file content'))
AttributeError: 'FileField' object has no attribute 'save'

这是我的models.py-

from django.contrib.contenttypes import generic
from django.contrib.auth.models import User, Group
from django.db import models
from mezzanine.pages.models import Page, RichText
from mezzanine.core.models import Ownable
from hs_core.models import AbstractResource
from hs_core.models import resource_processor
from mezzanine.pages.page_processors import processor_for
from suds.client import Client
from django.core.files.base import ContentFile
from django.core.files import File

class TimeSeries(Page, RichText, AbstractResource, models.Model):
    resource_description = models.TextField(null=False, blank=True, default='',
        help_text ='I.E. Upper Provo River Flow',
    )
    resource_url = models.TextField(max_length=100,null=False, blank=True, default='',
        help_text ="The WSDL Url for your web services- I.E. 'http://worldwater.byu.edu/interactive/dr/services/index.php/services/cuahsi_1_1.asmx?WSDL'"
    )
    resource_namespace=models.TextField(max_length=100,null=False, blank=True, default='',
        help_text ='The namespace is probably {http://www.cuahsi.org/waterML/1.1/}'
    )
    resource_file = models.FileField(upload_to='Time Series File', null=True, blank=True)

    ###Suds Call###
    client = Client(resource_url, cache=None)
    response = client.service.GetValues()  # a waterml file? (which is a type of xml file)

    response.open
    resource_file.save('Time Series File', File(response))
    class Meta:
        verbose_name = "Time Series"

processor_for(TimeSeries)(resource_processor)

0 个答案:

没有答案