你好(请原谅我的英语不好: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 通用 View 与 SomeOtherModel 一起使用,但它不起作用:
from django.views.generic.date_based import archive_index
archive_index(request, SometherModel.objects.all(), 'related__published_at')
错误来自 archive_index 第 28 行(使用 django 1.1):
date_list = queryset.dates(date_field, 'year')[::-1]
引发的异常是:
SomeOtherModel has no field named 'related__published_at'
你有解决办法吗?
非常感谢:)
通过深入研究 Django 源代码,通用 View archive_index
似乎不支持 GenericRelation
的相关字段。
这是因为查询集方法dates
不支持泛型关系。考虑将此作为错误/功能请求提交到 Django 错误跟踪器上。
我是一名优秀的程序员,十分优秀!