Django Tutorial Part 1'Poll'对象不会改变 [英] Django Tutorial Part 1 'Poll' object doesn't change

查看:108
本文介绍了Django Tutorial Part 1'Poll'对象不会改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚用Django的教程 - 第1部分:撰写您的第一个应用程序。当我想使用这个命令 Poll.objects.all()在python shell中查看我的Poll对象时,我看到 [< Poll:Poll object> ;] ,但是我更改了我的 models.py 并添加了

  class Poll(models.Model):
def __unicode __(self):
return self.question

class Choice(models.Model)
def __unicode __(self):
return self.choice

但我应该看到这个:

  [<民意调查:什么事?&$] 
/ pre>

有什么问题?

解决方案

终于找到了我的答案:



根据教程,我把这段代码添加到我的models.py中:



def was_published_today(self):

return self.pub_date。 date()== datetime.date.today()



但是当我删除这两行时,我可以看到怎么了?而不是 [<投票:投票对象>] !我不知道为什么会发生这种情况呢?但它只是工作!

我是新来的django和python,但我认为这是因为没有定义was_published_today在Poll类?他们可能只是错过了...


I'm new to Django with its tutorial -part 1 : Write your first app. when I want to see my Poll objects in python shell with this command Poll.objects.all(), I see [<Poll: Poll object>], however I've changed my models.py and added

class Poll(models.Model):   
    def __unicode__(self):  
        return self.question  

class Choice(models.Model):    
    def __unicode__(self):       
        return self.choice

but I should see this:

[<Poll: What's up?>]

What's the problem?

解决方案

finally I found my answer:

according to the tutorial, I added this code to my models.py :

def was_published_today(self):
return self.pub_date.date() == datetime.date.today()

but when I remove these two lines, I can see "what's up?" and not [<Poll: Poll object>] !! I don't know why this happen exactly? but it just worked!
I'm new to django and python but i think this caused for not defining was_published_today under Poll class?! they probably just missed it...

这篇关于Django Tutorial Part 1'Poll'对象不会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆