Cac*_*aco 1 python django traceback
我在models.py中有一个耐心的课程
class Patient(models.Model):
cpf_id = models.CharField(null=True, blank=True, max_length=15, unique=True, validators=[validate_cpf])
rg_id = models.CharField(max_length=15, null=True, blank=True)
name_txt = models.CharField(max_length=50)
number_record = models.AutoField(primary_key=True)
medical_record_number = models.CharField(max_length=25, null=True, blank=True)
natural_of_txt = models.CharField(max_length=50, null=True, blank=True)
citizenship_txt = models.CharField(max_length=50, null=True, blank=True)
street_txt = models.CharField(max_length=50, null=True, blank=True)
class Meta:
permissions = (
("view_patient", "Can view patient"),
)
def __unicode__(self): # Python 3: def __str__(self):
return \
self.name_txt, self.cpf_id, self.rg_id, self.medical_record_number, self.natural_of_txt, \
self.citizenship_txt, self.street_txt
Run Code Online (Sandbox Code Playgroud)
例如,当我将变量归于所有对象或使用某些过滤器过滤某些对象时,
patient = Patient.objects.all()
Run Code Online (Sandbox Code Playgroud)
好的,没有消息错误。
但是当我尝试列出此对象时,出现以下消息错误
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 74, in __repr__
return repr(data)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 423, in __repr__
u = six.text_type(self)
TypeError: coercing to Unicode: need string or buffer, tuple found
Run Code Online (Sandbox Code Playgroud)
编辑:
当我在shell中输入数字时,该代码就会发生
>>> patient
Run Code Online (Sandbox Code Playgroud)
列出我创建的对象
>>>> patient = Patient.objects.all()
Run Code Online (Sandbox Code Playgroud)
__unicode__() 应该返回一个字符串,而不是元组:
def __unicode__(self):
return self.name_txt
Run Code Online (Sandbox Code Playgroud)