im cố gắng thực hiện hướng dẫn django từ trang web django và ive gặp sự cố: ive phải thêm các phương thức __unicode__
vào lớp mô hình của tôi, nhưng khi nào tôi cố gắng để trở lại các đối tượng của mô hình tôi nhận được lỗi sau:lỗi django: đối tượng 'unicode' không được gọi là
in __unicode__
return self.question()
TypeError: 'unicode' object is not callable
im khá mới để trăn và rất mới để django, và tôi không thể thực sự nhìn thấy những gì ive bị mất ở đây, nếu ai đó có thể trỏ nó ra id rất biết ơn. Một chút mã:
models.py của tôi:
# The code is straightforward. Each model is represented by a class that subclasses django.db.models.Model. Each model has a number of
# class variables, each of which represents a database field in the model.
from django.db import models
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.question
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()
def __unicode__(self):
return self.choice()
và trong vỏ tương tác:
from pysite.polls.models import Poll, Choice
Poll.objects.all()
tại chỗ, cảm ơn sự giúp đỡ. – richzilla
chính xác những gì tôi cần biết cho trường hợp khác. Cảm ơn bạn. – ihightower