标签: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: O‘Reilly>]
错误:添加__unicode__()方法无效果。
——————————————————————————分割线——————————————————————————————————————
django book学习问题记录,布布扣,bubuko.com
标签:style blog http color strong 问题 div log
原文地址:http://www.cnblogs.com/Simon-xm/p/3895802.html