我目前正在阅读 Djangobook 教程的第 6 章。我按照说明进行操作,直到一切正常!!!
我将 date_hierarchy = 'publication_date' 添加到我的代码中
class BookAdmin(admin.ModelAdmin):
list_display = ('title', 'publisher', 'publication_date',)
list_filter = ('publication_date',)
search_fields = ('title',)
date_hierarchy = 'publication_date'
以上是我到目前为止在我的 admin.py 模型上的内容。
我得到的错误是
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/books/book/
Django Version: 1.4.3
Exception Type: AttributeError
Exception Value:
'unicode' object has no attribute 'year'
Exception Location: /usr/local/lib/python2.7/dist-packages/django/contrib/admin/templatetags/admin_list.py in date_hierarchy, line 302
Python Executable: /usr/bin/python
Python Version: 2.7.3
Python Path:
['/home/bradford/Development/Djangocode/mysite',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PIL',
'/usr/lib/python2.7/dist-packages/gst-0.10',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
'/usr/lib/python2.7/dist-packages/ubuntuone-client',
'/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
'/usr/lib/python2.7/dist-packages/ubuntuone-couch',
'/usr/lib/python2.7/dist-packages/ubuntuone-installer',
'/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']
Server time: Sun, 3 Feb 2013 03:42:02 -0600
不太确定该怎么做!任何帮助表示赞赏!
class Book(models.Model):
title = models.CharField(max_length = 100)
authors = models.ManyToManyField(Author)
publisher = models.ForeignKey(Publisher)
publication_date = models.DateField(blank = True, null = True)
def __unicode__(self):
return self.title