django错误:'unicode'对象不可调用

ric*_*lla 8 python django

我试图从django网站上做django教程,我遇到了一个问题:我必须将我的__unicode__方法添加到我的模型类中,但是当我尝试返回该模型的对象时,我得到以下错误:

in __unicode__
    return self.question()
TypeError: 'unicode' object is not callable
Run Code Online (Sandbox Code Playgroud)

我是相当新的python和django的新手,我真的不知道我错过了什么,如果有人可以指出它id非常感激.一点代码:

我的models.py:

# 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()
Run Code Online (Sandbox Code Playgroud)

并在交互式shell中:

from pysite.polls.models import Poll, Choice
Poll.objects.all()
Run Code Online (Sandbox Code Playgroud)

Pi *_*ort 29

self.choice是一个字符串值,但代码试图像函数一样调用它.只需删除它()之后.