码迷,mamicode.com
首页 > 其他好文 > 详细

django book学习问题记录

时间:2014-08-06 22:49:42      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   strong   问题   div   log   

——————————————————————————————————

位置:第五章《模型》

问题描述:

>>> p1 = Publisher.objects.create(name=Apress,
...     address=2855 Telegraph Avenue,
...     city=Berkeley, state_province=CA, country=U.S.A.,
...     website=http://www.apress.com/)
>>> p2 = Publisher.objects.create(name="O‘Reilly",
...     address=10 Fawcett St., city=Cambridge,
...     state_province=MA, country=U.S.A.,
...     website=http://www.oreilly.com/)
>>> publisher_list = Publisher.objects.all()
>>> publisher_list
[<Publisher: Publisher object>, <Publisher: Publisher object>] 
#当我们打印整个publisher列表时,我们没有得到想要的有用信息,无法把对象区分开来:

为mysite\books\modules里的三个模型添加__unicode__()方法后,就可以看到效果了:

>>> from books.models import Publisher
>>> publisher_list = Publisher.objects.all()
>>> publisher_list
[<Publisher: Apress>, <Publisher: OReilly>]

错误:添加__unicode__()方法无效果。

——————————————————————————分割线——————————————————————————————————————

django book学习问题记录,布布扣,bubuko.com

django book学习问题记录

标签:style   blog   http   color   strong   问题   div   log   

原文地址:http://www.cnblogs.com/Simon-xm/p/3895802.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!