【发布时间】:2013-02-24 14:38:56
【问题描述】:
更新
我正在对服务器进行一些维护并重新启动......一旦它回来,代码就可以正常工作......这实际上让我同样担心......
我认为这是 mod_wsgi 的一个错误。
还是谢谢!
我真的是 django 的新手(昨天开始)。我设法使用 xlrd 制作了一个 excel 解析器,数据一切正常(它加载非常快),我需要更新数据库中的文件信息,这样我就可以知道负载是如何进行的,这就是我拥有的地方问题,save() 方法不起作用,我已经使用了 update 以及 get 和 filter,但总是同样的问题。
希望大家能指出错误在哪里
models.py
class archivo(models.Model):
archivo_id = models.AutoField(primary_key=True)
fk_cliente = models.IntegerField()
fk_usuario = models.IntegerField()
archivo_nombre = models.CharField(max_length = 30)
archivo_original = models.CharField(max_length = 255)
archivo_extension = models.CharField(max_length = 5)
archivo_tamano = models.FloatField()
archivo_registros = models.IntegerField()
archivo_registros_buenos = models.IntegerField()
archivo_registros_malos = models.IntegerField()
archivo_registros_cargados = models.IntegerField()
archivo_fecha_carga = models.DateTimeField()
archivo_fecha_envio = models.DateTimeField()
def __unicode__(self):
return self.archivo_id
views.py
from procesa.models import *
from django.conf import settings
from django.shortcuts import render_to_response
import xlrd
from time import strftime
from symbol import except_clause
def procesa(request, procesar = 0):
datos = None
infoarchivo = None
if(procesar > 0):
try:
infoarchivo = archivo.objects.get(archivo_id=int(procesar))
except:
return render_to_response('error.html')
if (infoarchivo is not None):
excel_path = settings.FILES_URL+infoarchivo.archivo_original
wb = xlrd.open_workbook(str(excel_path))
sh = wb.sheet_by_index(0)
##START UPDATE##
infoarchivo2 = archivo.objects.filter(archivo_id = procesar)
infoarchivo2.archivo_registros = sh.nrows
infoarchivo2.save()
##END UPDATE##
for rownum in range(sh.nrows):
destino = str(sh.cell(rownum,0).value)
destino = destino.replace(".0","")
if (int(destino) > 0):
mensaje = str(sh.cell(rownum,1).value)
ahora = strftime("%Y-%m-%d %H:%M:%S")
reg = registro.objects.filter(registro_destino__exact=destino,fk_archivo__exact=procesar)
#reg = registro.objects.raw(str(el_query))
if (reg.exists()):
exists = True
else:
r = registro(fk_cliente=1,fk_usuario=1,fk_archivo=int(procesar),registro_destino=destino,registro_mensaje=mensaje,registro_estado='Cargado',registro_fecha_carga=ahora)
r.save()
datos = {'ID':procesar,'PATH': settings.FILES_URL, 'INFO':infoarchivo, 'el_excel':infoarchivo.archivo_original, 'registros':sh.nrows }
return render_to_response('carga.html', {'datos': datos})
在我已经尝试过的##START UPDATE## 块中
infoarchivo.archivo_registros = sh.nrows
infoarchivo.save()
和
archivo.objects.filter(archivo_id = procesar).update(archivo_registros=sh.nrows)
和
archivo.objects.get(archivo_id = procesar).update(archivo_registros=sh.nrows)
我在模型文件中找不到对此错误的任何引用或其他要添加的内容,我很确定这很容易修复,但我就是找不到。
我得到的错误(对于所有不同的代码)是
异常类型:AttributeError at /procesa/4
异常值:'archivo' 对象没有属性'update'
文件的记录被解析并插入没有问题。
我在 Apache 2.2 中使用 Django 1.5 和 python 2.7,并在 Amazon 的 EC2 中安装了 mod_wsgi 和 mysql 后端
更新 我正在对服务器进行一些维护并重新启动......一旦它回来,代码就可以正常工作......这实际上让我同样担心......
我认为这是 mod_wsgi 的一个错误。
还是谢谢!
【问题讨论】:
-
您覆盖了您未在模型中定义的更新。重写您使用更新方法的代码或在模型中定义更新方法以便您可以使用它
标签: django python-2.7 attributes