1
我在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
當我屬性的所有對象的變量或過濾器,使用例如某些對象的Django蟒誤差,
patient = Patient.objects.all()
好的,沒有消息錯誤。
但是當我嘗試列表這個對象,我收到以下消息錯誤
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
編輯:
發生時的代碼,當我在外殼位
>>> patient
列出對象我創建了
>>>> patient = Patient.objects.all()