現在、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