適切な Google グループ (http://groups.google.com/group/django-non-relational/browse_thread/thread/a51c1903af175e1c) で質問しましたが、開発者は今ちょっと忙しいようです。未回答のまま。ここで私の問題の解決策が見つかることを願っています。
本質は: Django-nonrel + GAE + Blog App from Django Basic apps アプリ の管理パネルから新しいブログ投稿を作成しようとしました。そして、次の例外を受け取りました:
DatabaseError: Lookup type 'month' isn't supported
関連するGoogleグループでこれについて尋ねたところ、django-dbindexerを使用するように回答されました。その説明に関しては、まさに私が必要としているものなので、すべての手順をガイドし、アプリに「添付」しました。インデックス作成は完了しましたが、同じ例外が発生します。完全なトレースは次のとおりです。
Traceback (most recent call last):
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\core\handlers\base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\contrib\admin\options.py", line 308, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\utils\decorators.py", line 93, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\views\decorators\cache.py", line 79, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\contrib\admin\sites.py", line 190, in inner
return view(request, *args, **kwargs)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\utils\decorators.py", line 28, in _wrapper
return bound_func(*args, **kwargs)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\utils\decorators.py", line 93, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\utils\decorators.py", line 24, in bound_func
return func(self, *args2, **kwargs2)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\db\transaction.py", line 282, in inner
res = func(*args, **kwargs)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\contrib\admin\options.py", line 852, in add_view
if form.is_valid():
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\forms\forms.py", line 121, in is_valid
return self.is_bound and not bool(self.errors)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\forms\forms.py", line 112, in _get_errors
self.full_clean()
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\forms\forms.py", line 269, in full_clean
self._post_clean()
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\forms\models.py", line 338, in _post_clean
self.validate_unique()
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\forms\models.py", line 347, in validate_unique
self.instance.validate_unique(exclude=exclude)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\db\models\base.py", line 669, in validate_unique
date_errors = self._perform_date_checks(date_checks)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\db\models\base.py", line 791, in _perform_date_checks
if qs.exists():
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\db\models\query.py", line 498, in exists
return self.query.has_results(using=self.db)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\django\db\models\sql\query.py", line 428, in has_results
return compiler.has_results()
File "F:\Its_mine19\Programming\Java\pineapplemon\src\djangotoolbox\db\basecompiler.py", line 222, in has_results
return self.get_count(check_exists=True)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\djangotoolbox\db\basecompiler.py", line 269, in get_count
return self.build_query().count(high_mark)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\djangotoolbox\db\basecompiler.py", line 275, in build_query
query.add_filters(self.query.where)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\djangotoolbox\db\basecompiler.py", line 72, in add_filters
self.add_filters(child)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\djangotoolbox\db\basecompiler.py", line 76, in add_filters
self.add_filter(column, lookup_type, self._negated, db_type, value)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\djangoappengine\db\compiler.py", line 57, in _func
return func(*args, **kwargs)
File "F:\Its_mine19\Programming\Java\pineapplemon\src\djangoappengine\db\compiler.py", line 211, in add_filter
raise DatabaseError("Lookup type %r isn't supported" % lookup_type)
DatabaseError: Lookup type 'month' isn't supported
これが私のデータモデルです(basic.blog.modelsから):
class Post(models.Model):
"""Post model."""
STATUS_CHOICES = (
(1, _('Draft')),
(2, _('Public')),
)
title = models.CharField(_('title'), max_length=200)
slug = models.SlugField(_('slug'), unique_for_date='publish')
author = models.ForeignKey(User, blank=True, null=True)
body = models.TextField(_('body'), )
tease = models.TextField(_('tease'), blank=True, help_text=_('Concise text suggested. Does not appear in RSS feed.'))
status = models.IntegerField(_('status'), choices=STATUS_CHOICES, default=2)
allow_comments = models.BooleanField(_('allow comments'), default=True)
publish = models.DateTimeField(_('publish'), default=datetime.datetime.now)
created = models.DateTimeField(_('created'), auto_now_add=True)
modified = models.DateTimeField(_('modified'), auto_now=True)
categories = models.ManyToManyField(Category, blank=True)
tags = TagField()
objects = PublicManager()
class Meta:
verbose_name = _('post')
verbose_name_plural = _('posts')
db_table = 'blog_posts'
ordering = ('-publish',)
get_latest_by = 'publish'
def __unicode__(self):
return u'%s' % self.title
@permalink
def get_absolute_url(self):
return ('blog_detail', None, {
'year': self.publish.year,
'month': self.publish.strftime('%b').lower(),
'day': self.publish.day,
'slug': self.slug
})
def get_previous_post(self):
return self.get_previous_by_publish(status__gte=2)
def get_next_post(self):
return self.get_next_by_publish(status__gte=2)
これが私のアプリのdbindexesモジュール(basic.blog.dbindexes)にあるものです:
from basic.blog.models import Post
from dbindexer.api import register_index
register_index(Post, {
'publish': 'month',
# 'created': 'month',
# 'modified': 'month',
})
import logging
logger = logging.getLogger(__name__)
logger.info('Basic.blog dbindexes') # Logging statement to check if this module is ever executed to be sure indexing is done
助けてくれてありがとう。