我是 django 的新手,我正在尝试使用 get_or_create 模型函数,但即使我的模型中有该属性,我也会收到错误消息
AttributeError at /professor/adicionar-compromisso
'tuple' object has no attribute 'dias'
Request Method: POST
Request URL: http://localhost:8000/professor/adicionar-compromisso
Django Version: 1.4.1
Exception Type: AttributeError
Exception Value:
'tuple' object has no attribute 'dias'
Exception Location: c:\htdocs\rpv\GerenDisponibilidade\professor\models.py in inserirCompromisso, line 63
Python Executable: C:\Python27\python.exe
Python Version: 2.7.3
Python Path:
['c:\\htdocs\\rpv\\GerenDisponibilidade',
'C:\\Python27\\lib\\site-packages\\distribute-0.6.27-py2.7.egg',
'C:\\Python27\\lib\\site-packages\\pip-1.1-py2.7.egg',
'C:\\Python27\\lib\\site-packages\\sphinx-1.1.3-py2.7.egg',
'C:\\Python27\\lib\\site-packages\\docutils-0.9.1-py2.7.egg',
'C:\\Python27\\lib\\site-packages\\jinja2-2.6-py2.7.egg',
'C:\\Python27\\lib\\site-packages\\pygments-1.5-py2.7.egg',
'C:\\Windows\\system32\\python27.zip',
'C:\\Python27\\DLLs',
'C:\\Python27\\lib',
'C:\\Python27\\lib\\plat-win',
'C:\\Python27\\lib\\lib-tk',
'C:\\Python27',
'C:\\Python27\\lib\\site-packages',
'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info']
Server time: Seg, 3 Set 2012 17:57:17 -0300
模型
class DiaSemana(models.Model):
DIAS_CHOICES = (
("Seg", "Segunda-Feira"),
("Ter", "Terça-Feira"),
("Qua", "Quarta-Feira"),
("Qui", "Quinta-Feira"),
("Sex", "Sexta-Feira"),
("Sab", "Sábado"),
("Dom", "Domingo"),
)
dias = models.CharField(max_length=20, choices=DIAS_CHOICES)
在这里我试图搜索以检查是否存在现有值,否则创建新值并保存
for diaSemana in diaSemanas:
d = DiaSemana.objects.get_or_create(dias=diaSemana)
d.dias = diaSemana;
d.save()
c.save()
c.diaSemana.add(d);
怎么了?