你好(请原谅我丑陋的英语:p),
想象一下这两个简单的模型:
from django.contrib.contenttypes import generic
from django.db import models
class SomeModel(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField(_('object id'))
content_object = generic.GenericForeignKey('content_type', 'object_id')
published_at = models.DateTimeField('Publication date')
class SomeOtherModel(models.Model):
related = generic.GenericRelation(SomeModel)
我想将 archive_index 通用视图与 SomeOtherModel 一起使用,但它不起作用:
from django.views.generic.date_based import archive_index
archive_index(request, SometherModel.objects.all(), 'related__published_at')
错误来自第 28 行的 archive_index(使用 django 1.1):
date_list = queryset.dates(date_field, 'year')[::-1]
引发的异常是:
SomeOtherModel has no field named 'related__published_at'
你有什么想法来解决它吗?
非常感谢你 :)