我正在使用django-hitcont来计算我的 Post 模型的视图。我正在尝试使用此查询在我的 ListView 中获得观看次数最多的帖子,objects.order_by('hit_count_generic__hits')
它在 SQLite 上运行良好,但在 PostgreSQL 上,它给了我这个错误:
django.db.utils.ProgrammingError: operator does not exist: integer = text LINE 1: ...R JOIN "hitcount_hit_count" ON ("posts_post"."id" = "hitcoun...
。
模型.py
class Post(models.Model, HitCountMixin):
author = models.ForeignKey(User, related_name='authors', on_delete=models.CASCADE)
title = models.CharField('Post Title', max_length = 150)
description = models.TextField('Description', max_length=1000, blank = True)
date_posted = models.DateTimeField('Date posted', default = timezone.now)
date_modifed = models.DateTimeField('Date last modified', default = timezone.now)
document = models.FileField('Document of Post', upload_to='documents', \
validators=[FileExtensionValidator(allowed_extensions = ['pdf', 'docx']), validate_document_size] \
)
hit_count_generic = GenericRelation(
HitCount,
object_id_field='object_pk',
related_query_name='hit_count_generic_relation'
)
视图.py
queryset = Post.objects.order_by('hit_count_generic__hits')
我在 Github 上发现了与该问题相关的这个问题,但我仍然无法找出提到的解决方法。