管理站点属性错误

时间:2016-02-15 02:52:32

标签: python django django-admin

我浏览了django在线教程,我基本上试图通过自己的一些修改来复制教程。当我创建自己的模型请求和响应,我去管理网站查看这些模型,它不会让我看看响应,我得到一个错误:

    Exception Type: AttributeError
    Exception Value:    
    'Response' object has no attribute 'response'
I am doing the same exact thing they did in the tutorial, and i even put the tutorial code in below my code and the tutorial code works fine, i am not sure what is going on: 

models.py:

 class Request(models.Model):
        vive_title = models.CharField(max_length=200)
        # pub_date = models.DateField('date published', default=datetime.date.today)
        # location = models.CharField(max_length=100, default="Not Location Specific")

        def __str__(self):
            return self.vive_title


    class Response(models.Model):
        request = models.ForeignKey(Request)
        response_text = models.CharField(max_length=200)
        # pub_date = models.DateTimeField("time of response")
        votes = models.IntegerField(default=0)

        def __str__(self):
            return self.response


    class Question(models.Model):
        question_text = models.CharField(max_length=200)
        pub_date = models.DateTimeField('date published')

        def __str__(self):  # __unicode__ on Python 2
            return self.question_text


    class Choice(models.Model):
        question = models.ForeignKey(Question)
        choice_text = models.CharField(max_length=200)
        votes = models.IntegerField(default=0)

        def __str__(self):  # __unicode__ on Python 2
            return self.choice_text

admin.py

from .models import Response, Request, Question, Choice

admin.site.register(Request)
admin.site.register(Response)
admin.site.register(Choice)
admin.site.register(Question)

1 个答案:

答案 0 :(得分:1)

class Response(models.Model):
        request = models.ForeignKey(Request)
        response_text = models.CharField(max_length=200)
        # pub_date = models.DateTimeField("time of response")
        votes = models.IntegerField(default=0)

        def __str__(self):
            return self.response

此课程没有 self.response 。只有request,response_text和votes。您需要返回其他值。